Skip to content

Instantly share code, notes, and snippets.

@shanelau
Forked from anonymous/index.html
Last active December 8, 2016 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanelau/42e027b8db40cb63e9695a7b917137d1 to your computer and use it in GitHub Desktop.
Save shanelau/42e027b8db40cb63e9695a7b917137d1 to your computer and use it in GitHub Desktop.
DOMAIN: HTTPS 改造, 替换所有的非 https 域名。新增代码直接使用 https 域名// source http://jsbin.com/citocaz
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTFa-8" />
<title>demo: HTTPS 改造</title>
<meta content="魅玩帮是一个提供智能硬件免费申请试玩的导购平台,我们筛选市面上最为前沿、时尚、实用和专业的硬件产品免费提供给用户进行试用,为其他用户在购买前提供有价值的决策参考。" name="description" />
<meta content="魅玩帮,可穿戴, 可穿戴设备, 智能设备, 智能可穿戴设备, 便携设备, 便携智能设备, 奇酷网, 奇酷,360 奇酷, 小米酷玩, 点名时间,牛玩,魅族智能硬件, 智能硬件,硬件, 智能移动设备, 免费试用, 苹果,评测,测评, 智能手环, 智能家居, 智能手表, 智能电视 " name="keywords" />
<meta content="True" name="HandheldFriendly" />
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
<meta content="width=device-width,initial-scale=1,maximum-scale=1" name="viewport" />
<link href="http://res.wan.meizu.com/wan-res/favicon.ico" rel="shortcut icon" />
<link href="http://res.wan.meizu.com/wan-res/min/styles/index.f644d1fc.css" rel="stylesheet" />
<!--[if lt IE 9]>
<script src="http://cdnjscn.b0.upaiyun.com/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="http://cdnjscn.b0.upaiyun.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="app-download-hint">
<div class="open wrapper">
<img class="screen-shot" src="http://res.wan.meizu.com/wan-res/images/ss-hint-open.png" />
<img class="slogon" src="http://res.wan.meizu.com/wan-res/images/dl-hint-open.png" />
<a href="http://wan.meizu.com/about/download.html" class="download-btn">下载 APP</a>
<button class="close"></button>
</div>
<div class="close wrapper">
<img class="screen-shot" src="http://wan-pro.b0.upaiyun.com/wan-res/images/ss-hint-close.png" />
<button class="close"></button>
<a href="http://wan.meizu.com/about/download.html" class="download-btn">下载 APP</a>
<img class="slogon" src="http://res.wan.meizu.com/wan-res/images/dl-hint-close.png" />
</div>
</div>
<script id="jsbin-javascript">
/**
*@dom {String} str
*@config {Object} key value, replace all key in dom by value
*/
function replaceDomain(dom, config){
var keys = Object.keys(config);
for(var i=0;i < keys.length; i++){
var reg = new RegExp(keys[i], 'g');
dom = dom.replace(reg, config[keys[i]]);
}
return dom;
}
//http://stackoverflow.com/questions/3430455/document-ready-source
/**
* document ready event
*/
(function(funcName, baseObj) {
// The public function name defaults to window.docReady
// but you can pass in your own object and own function name and those will be used
// if you want to put them in a different namespace
funcName = funcName || "docReady";
baseObj = baseObj || window;
var readyList = [];
var readyFired = false;
var readyEventHandlersInstalled = false;
// call this when the document is ready
// this function protects itself against being called more than once
function ready() {
if (!readyFired) {
// this must be set to true before we start calling callbacks
readyFired = true;
for (var i = 0; i < readyList.length; i++) {
// if a callback here happens to add new ready handlers,
// the docReady() function will see that it already fired
// and will schedule the callback to run right after
// this event loop finishes so all handlers will still execute
// in order and no new ones will be added to the readyList
// while we are processing the list
readyList[i].fn.call(window, readyList[i].ctx);
}
// allow any closures held by these functions to free
readyList = [];
}
}
function readyStateChange() {
if ( document.readyState === "complete" ) {
ready();
}
}
// This is the one public interface
// docReady(fn, context);
// the context argument is optional - if present, it will be passed
// as an argument to the callback
baseObj[funcName] = function(callback, context) {
// if ready has already fired, then just schedule the callback
// to fire asynchronously, but right away
if (readyFired) {
setTimeout(function() {callback(context);}, 1);
return;
} else {
// add the function and context to the list
readyList.push({fn: callback, ctx: context});
}
// if document already ready to go, schedule the ready function to run
if (document.readyState === "complete") {
setTimeout(ready, 1);
} else if (!readyEventHandlersInstalled) {
// otherwise if we don't have event handlers installed, install them
if (document.addEventListener) {
// first choice is DOMContentLoaded event
document.addEventListener("DOMContentLoaded", ready, false);
// backup is window load event
window.addEventListener("load", ready, false);
} else {
// must be IE
document.attachEvent("onreadystatechange", readyStateChange);
window.attachEvent("onload", ready);
}
readyEventHandlersInstalled = true;
}
}
})("docReady", window);
var DOMAINS = {
"http://image.wan.meizu.com": "https://wan-img.res.meizu.com",
"http://res.wan.meizu.com" : "//wan.res.meizu.com",
"http://wan-pro.b0.upaiyun.com": "//wan-img.res.meizu.com",
"http://wan-dev.b0.upaiyun.com" : "//wan-dev.b0.upaiyun.com"
}
function updateHTTPSDomain(){
var html = document.getElementsByTagName('html')[0];
html.innerHTML = replaceDomain(html.innerHTML, DOMAINS);
console.log(html.innerHTML);
}
docReady(updateHTTPSDomain);
</script>
</body>
</html>
/**
*@dom {String} str
*@config {Object} key value, replace all key in dom by value
*/
function replaceDomain(dom, config){
var keys = Object.keys(config);
for(var i=0;i < keys.length; i++){
var reg = new RegExp(keys[i], 'g');
dom = dom.replace(reg, config[keys[i]]);
}
return dom;
}
//http://stackoverflow.com/questions/3430455/document-ready-source
/**
* document ready event
*/
(function(funcName, baseObj) {
// The public function name defaults to window.docReady
// but you can pass in your own object and own function name and those will be used
// if you want to put them in a different namespace
funcName = funcName || "docReady";
baseObj = baseObj || window;
var readyList = [];
var readyFired = false;
var readyEventHandlersInstalled = false;
// call this when the document is ready
// this function protects itself against being called more than once
function ready() {
if (!readyFired) {
// this must be set to true before we start calling callbacks
readyFired = true;
for (var i = 0; i < readyList.length; i++) {
// if a callback here happens to add new ready handlers,
// the docReady() function will see that it already fired
// and will schedule the callback to run right after
// this event loop finishes so all handlers will still execute
// in order and no new ones will be added to the readyList
// while we are processing the list
readyList[i].fn.call(window, readyList[i].ctx);
}
// allow any closures held by these functions to free
readyList = [];
}
}
function readyStateChange() {
if ( document.readyState === "complete" ) {
ready();
}
}
// This is the one public interface
// docReady(fn, context);
// the context argument is optional - if present, it will be passed
// as an argument to the callback
baseObj[funcName] = function(callback, context) {
// if ready has already fired, then just schedule the callback
// to fire asynchronously, but right away
if (readyFired) {
setTimeout(function() {callback(context);}, 1);
return;
} else {
// add the function and context to the list
readyList.push({fn: callback, ctx: context});
}
// if document already ready to go, schedule the ready function to run
if (document.readyState === "complete") {
setTimeout(ready, 1);
} else if (!readyEventHandlersInstalled) {
// otherwise if we don't have event handlers installed, install them
if (document.addEventListener) {
// first choice is DOMContentLoaded event
document.addEventListener("DOMContentLoaded", ready, false);
// backup is window load event
window.addEventListener("load", ready, false);
} else {
// must be IE
document.attachEvent("onreadystatechange", readyStateChange);
window.attachEvent("onload", ready);
}
readyEventHandlersInstalled = true;
}
}
})("docReady", window);
var DOMAINS = {
"http://image.wan.meizu.com": "https://wan-img.res.meizu.com",
"http://res.wan.meizu.com" : "//wan.res.meizu.com",
"http://wan-pro.b0.upaiyun.com": "//wan-img.res.meizu.com",
"http://wan-dev.b0.upaiyun.com" : "//wan-dev.b0.upaiyun.com"
}
function updateHTTPSDomain(){
var html = document.getElementsByTagName('html')[0];
html.innerHTML = replaceDomain(html.innerHTML, DOMAINS);
console.log(html.innerHTML);
}
docReady(updateHTTPSDomain);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment