`);
},
};
if (isGM) {
GMsetValue = GM.setValue;
GMgetValue = GM.getValue;
GMdeleteValue = GM.deleteValue;
GMregisterMenuCommand = GM.registerMenuCommand;
GMunregisterMenuCommand = () => {};
GMopenInTab = GM.openInTab;
} else {
GMsetValue = GM_setValue;
GMgetValue = GM_getValue;
GMdeleteValue = GM_deleteValue;
GMregisterMenuCommand = GM_registerMenuCommand;
GMunregisterMenuCommand = GM_unregisterMenuCommand;
GMopenInTab = GM_openInTab;
}
/* Refactoring NoticeJs Functions */
-(function (q, d) {
typeof exports === "object" && typeof module === "object"
? (window.module.exports = d())
: typeof define === "function" && window.define.amd
? window.define("NoticeJs", [], d)
: typeof exports === "object"
? (window.exports.NoticeJs = d())
: (q.NoticeJs = d());
})("undefined" !== typeof self ? self : this, function () {
return (function (q) {
let m = {};
function d(g) {
if (m[g]) {
return m[g].exports;
}
let l = (m[g] = {
i: g,
l: !1,
exports: {},
});
q[g].call(l.exports, l, l.exports, d);
l.l = !0;
return l.exports;
}
d.m = q;
d.c = m;
d.d = function (g, l, f) {
d.o(g, l) ||
Object.defineProperty(g, l, {
configurable: !1,
enumerable: !0,
get: f,
});
};
d.n = function (g) {
let l =
g && g.__esModule
? function () {
return g.default;
}
: function () {
return g;
};
d.d(l, "a", l);
return l;
};
d.o = function (g, l) {
return Object.prototype.hasOwnProperty.call(g, l);
};
d.p = "dist/";
return d((d.s = 2));
})([
function (q, d, m) {
Object.defineProperty(d, "__esModule", { value: !0 });
d.noticeJsModalClassName = `${Notice.noticejs}-modal`;
d.closeAnimation = `${Notice.noticejs}-fadeOut`;
d.Defaults = {
title: "",
text: "",
type: `${Notice.success}`,
position: "bottomRight",
newestOnTop: !1,
timeout: 30,
progressBar: !0,
indeterminate: !1,
closeWith: ["button"],
animation: {
open: `${Notice.animated} fadeIn`,
close: `${Notice.animated} fadeOut`,
},
modal: !1,
width: 400,
scroll: {
maxHeightContent: 400,
showOnHover: !0,
},
rtl: !1,
callbacks: {
beforeShow: [],
onShow: [],
afterShow: [],
onClose: [],
afterClose: [],
onClick: [],
onHover: [],
onTemplate: [],
},
};
},
function (q, d, m) {
function g(a, b) {
a.callbacks.hasOwnProperty(b) &&
a.callbacks[b].forEach(function (c) {
typeof c === "function" && c.apply(a);
});
}
Object.defineProperty(d, "__esModule", { value: !0 });
d.appendNoticeJs = d.addListener = d.CloseItem = d.AddModal = void 0;
d.getCallback = g;
let l = (function (a) {
if (a && a.__esModule) {
return a;
}
let b = {};
if (null !== a) {
for (let c in a) {
Object.prototype.hasOwnProperty.call(a, c) && (b[c] = a[c]);
}
}
b.default = a;
return b;
})(m(0));
let f = l.Defaults;
let h = (d.AddModal = function () {
if (0 >= document.getElementsByClassName(l.noticeJsModalClassName).length) {
let a = document.createElement("div");
a.classList.add(l.noticeJsModalClassName);
a.classList.add(`${Notice.noticejs}-modal-open`);
document.body.appendChild(a);
setTimeout(function () {
a.className = l.noticeJsModalClassName;
}, 200);
}
});
let n = (d.CloseItem = function (a) {
g(f, "onClose");
null !== f.animation && null !== f.animation.close && (a.className += " " + f.animation.close);
setTimeout(function () {
a.remove();
}, 200);
!0 === f.modal &&
1 <= document.querySelectorAll(`[${Notice.noticejs}-modal='true']`).length &&
((document.querySelector(`.${Notice.noticejs}-modal`).className += ` ${Notice.noticejs}-modal-close`),
setTimeout(function () {
document.querySelector(`.${Notice.noticejs}-modal`).remove();
}, 500));
let b = a.closest(`.${Notice.noticejs}`);
let c = b ? "." + b.className.replace(`${Notice.noticejs}`, "").trim() : ".null";
setTimeout(function () {
0 >= document.querySelectorAll(c + ` .${Notice.item}`).length && document.querySelector(c) && document.querySelector(c).remove();
}, 500);
});
let e = (d.addListener = function (a) {
f.closeWith.includes("button") &&
a.querySelector(`.${Notice.close}`).addEventListener("click", function () {
n(a);
});
f.closeWith.includes("click")
? ((a.style.cursor = "pointer"),
a.addEventListener("click", function (b) {
`${Notice.close}` !== b.target.className && (g(f, "onClick"), n(a));
}))
: a.addEventListener("click", function (b) {
`${Notice.close}` !== b.target.className && g(f, "onClick");
});
a.addEventListener("mouseover", function () {
g(f, "onHover");
});
});
d.appendNoticeJs = function (a, b, c) {
let p = `.${Notice.noticejs}-` + f.position;
let k = document.createElement("div");
k.classList.add(`${Notice.item}`);
k.classList.add(f.type);
!0 === f.rtl && k.classList.add(`${Notice.noticejs}-rtl`);
"" !== f.width && Number.isInteger(f.width) && (k.style.width = f.width + "px");
a && "" !== a && k.appendChild(a);
k.appendChild(b);
c && "" !== c && k.appendChild(c);
["top", "bottom"].includes(f.position) && (document.querySelector(p).innerHTML = "");
null !== f.animation && null !== f.animation.open && (k.className += " " + f.animation.open);
!0 === f.modal && (k.setAttribute(`${Notice.noticejs}-modal`, "true"), h());
e(k, f.closeWith);
g(f, "beforeShow");
g(f, "onShow");
!0 === f.newestOnTop ? document.querySelector(p).insertAdjacentElement("afterbegin", k) : document.querySelector(p).appendChild(k);
g(f, "afterShow");
return k;
};
},
function (q, d, m) {
function g(a) {
if (a && a.__esModule) {
return a;
}
let b = {};
if (null !== a) {
for (let c in a) {
Object.prototype.hasOwnProperty.call(a, c) && (b[c] = a[c]);
}
}
b.default = a;
return b;
}
Object.defineProperty(d, "__esModule", { value: !0 });
let l = (function () {
function a(b, c) {
for (let p = 0; p < c.length; p++) {
let k = c[p];
k.enumerable = k.enumerable || !1;
k.configurable = !0;
"value" in k && (k.writable = !0);
Object.defineProperty(b, k.key, k);
}
}
return function (b, c, p) {
c && a(b.prototype, c);
p && a(b, p);
return b;
};
})();
m(3);
let f = m(0);
let h = g(f);
let n = m(4);
m = m(1);
let e = g(m);
m = (function () {
class a {
constructor() {
let b = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {};
if (!(this instanceof a)) {
throw new TypeError("Cannot call a class as a function");
}
this.options = Object.assign(h.Defaults, b);
this.component = new n.Components();
this.id = `${Notice.noticejs}-` + defCon.randString(6);
this.on("beforeShow", this.options.callbacks.beforeShow);
this.on("onShow", this.options.callbacks.onShow);
this.on("afterShow", this.options.callbacks.afterShow);
this.on("onClose", this.options.callbacks.onClose);
this.on("afterClose", this.options.callbacks.afterClose);
this.on("onClick", this.options.callbacks.onClick);
this.on("onHover", this.options.callbacks.onHover);
}
}
l(
a,
[
{
key: "show",
value: function () {
let b = this.component.createContainer();
document.querySelector(`.${Notice.noticejs}-` + this.options.position) === null && document.body.appendChild(b);
let c = void 0;
b = this.component.createHeader(this.options.title, this.options.closeWith);
let p = this.component.createBody(this.options.text);
!0 === this.options.progressBar && (c = this.component.createProgressBar());
b = e.appendNoticeJs(b, p, c);
b.setAttribute("id", this.id);
return (this.dom = b);
},
},
{
key: "on",
value: function (b) {
let c = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : function () {};
typeof c === "function" && this.options.callbacks.hasOwnProperty(b) && this.options.callbacks[b].push(c);
return this;
},
},
{
key: "close",
value: function () {
e.CloseItem(this.dom);
},
},
],
[
{
key: "overrideDefaults",
value: function (b) {
this.options = Object.assign(h.Defaults, b);
return this;
},
},
]
);
return a;
})();
d.default = m;
q.exports = d.default;
},
function (q, d) {},
function (q, d, m) {
function g(n) {
if (n && n.__esModule) {
return n;
}
let e = {};
if (n === null) {
for (let a in n) {
Object.prototype.hasOwnProperty.call(n, a) && (e[a] = n[a]);
}
}
e.default = n;
return e;
}
Object.defineProperty(d, "__esModule", { value: !0 });
d.Components = void 0;
let l = (function () {
function n(e, a) {
for (let b = 0; b < a.length; b++) {
let c = a[b];
c.enumerable = c.enumerable || !1;
c.configurable = !0;
"value" in c && (c.writable = !0);
Object.defineProperty(e, c.key, c);
}
}
return function (e, a, b) {
a && n(e.prototype, a);
b && n(e, b);
return e;
};
})();
q = m(0);
q = g(q);
m = m(1);
let f = g(m);
let h = q.Defaults;
d.Components = (function () {
function n() {
if (!(this instanceof n)) {
throw new TypeError("Cannot call a class as a function");
}
}
l(n, [
{
key: "createContainer",
value: function () {
let e = `${Notice.noticejs}-` + h.position;
let a = document.createElement("div");
a.classList.add(`${Notice.noticejs}`);
a.classList.add(e);
return a;
},
},
{
key: "createHeader",
value: function () {
let e = void 0;
h.title && "" !== h.title && ((e = document.createElement("div")), e.setAttribute("class", `${Notice.noticejs}-heading`), (e.textContent = h.title));
if (h.closeWith.includes("button")) {
let a = document.createElement("div");
a.setAttribute("class", `${Notice.close}`);
a.innerHTML = "×";
e ? e.appendChild(a) : (e = a);
}
return e;
},
},
{
key: "createBody",
value: function () {
let e = document.createElement("div");
e.setAttribute("class", `${Notice.noticejs}-body`);
let a = document.createElement("div");
a.setAttribute("class", `${Notice.noticejs}-content`);
a.innerHTML = h.text;
e.appendChild(a);
null !== h.scroll &&
"" !== h.scroll.maxHeight &&
((e.style.overflowY = "auto"), (e.style.maxHeight = h.scroll.maxHeight + "px"), !0 === h.scroll.showOnHover && (e.style.visibility = "hidden"));
return e;
},
},
{
key: "createProgressBar",
value: function () {
let e = document.createElement("div");
e.setAttribute("class", `${Notice.noticejs}-progressbar`);
let a = document.createElement("div");
a.setAttribute("class", `${Notice.noticejs}-bar`);
e.appendChild(a);
let b = 100;
let c = 0;
let p = 0;
let k = "";
if (!0 === h.progressBar && "boolean" !== typeof h.timeout && !1 !== h.timeout) {
let u = function () {
if (0 >= b) {
clearInterval(p);
let r = e.closest(`div.${Notice.item}`);
if (null !== h.animation && null !== h.animation.close) {
r.className = r.className.replace(new RegExp("(?:^|\\s)" + h.animation.open + "(?:\\s|$)"), " ");
r.className += " " + h.animation.close;
let t = parseInt(h.timeout) + 500;
setTimeout(function () {
f.CloseItem(r);
}, t);
} else {
f.CloseItem(r);
}
} else {
b--;
a.style.width = b + "%";
}
};
let v = function () {
c === 0 ? (b--, b === 0 && (c = 1)) : (b++, b === 100 && (c = 0));
document.getElementById(k) === null ? clearInterval(p) : (a.style.width = b + "%");
};
!0 === h.indeterminate
? ((p = setInterval(v, h.timeout)), (k = `${Notice.noticejs}-progressbar-` + p), e.setAttribute("id", k))
: (p = setInterval(u, h.timeout));
}
return e;
},
},
]);
return n;
})();
},
]);
});
/* Refactoring functions of GMsetValue/GMgetValue/GMdeleteValue with Expire */
function GMsetExpire(key, value) {
let obj = {
data: value,
time: Date.now(),
};
GMsetValue(key, defCon.encrypt(JSON.stringify(obj)));
}
function GMgetExpire(key, val, _expire) {
let expire, expires, expireTime;
if (!val) {
return val;
}
val = JSON.parse(defCon.decrypt(val));
if (_expire) {
expire = /(?!^0)^[0-9]+[smhdw]$/i.test(_expire) ? _expire : "4h";
expire = expire.replace(/w/i, "*7*24*3600*1000").replace(/d/i, "*24*3600*1000").replace(/h/i, "*3600*1000").replace(/m/i, "*60*1000").replace(/s/i, "*1000");
expires = expire.split("*");
expireTime = expires.reduce(function (a, b) {
return a * b;
}, 1);
}
defCon.restTime = val.time + expireTime - Date.now();
if (defCon.restTime <= 0) {
GMdeleteValue(key);
return null;
}
return val.data;
}
/* Refactoring GMnotification Function */
GMnotification = (text = "", type = `${Notice.info}`, closeWith = true, timeout = 30, { ...options } = {}, position = "bottomRight") => {
try {
// eslint-disable-next-line no-undef
new NoticeJs({
text: text,
type: type,
closeWith: closeWith ? ["button"] : ["click"],
timeout: timeout,
callbacks: { ...options },
position: position,
}).show();
} catch (e) {
error("//-> %cGMnotification:\n%c%s", "font-weight:bold", "font-weight:normal", e);
}
};
const callback_Countdown = {
onShow: [
function (Interval = 3) {
const m = setInterval(() => {
Interval ? --Interval : clearInterval(m);
const emText = document.querySelector(`.${defCon.rName} dl dd em`);
if (emText) {
emText.innerHTML = Interval;
}
!Interval ? location.reload() : () => {};
}, 1e3);
},
],
};
/* Common functions */
function GetUrlParam(paraName) {
if (!paraName) {
const parameter = document.location.pathname.toString();
const arr = parameter.split("/");
return arr[1] === undefined ? "" : arr[1];
} else {
const url = document.location.toString();
const arrObj = url.split("?");
if (arrObj.length > 1) {
const arrPara = arrObj[1].split("&");
let arr;
for (let i = 0; i < arrPara.length; i++) {
arr = arrPara[i].split("=");
if (arr !== null && arr[0] === paraName) {
return arr[1];
}
}
return "";
} else {
return "";
}
}
}
function safeFunction(func) {
try {
func();
} catch (e) {
error("//-> %cFunctions:\n%c%s", "font-weight:bold", "font-weight:normal", e);
}
}
/* SYSTEM INFO */
if (window.self === window.top) {
console.info(
`%c[GB-Init]%c\nVersion: ${defCon.curVersion} %c[%s]%c\nExtension: %s\nlastRuntime: ${defCon.lastRuntime()}`,
"font-weight:bold;color:dodgerblue",
"color:0",
"color:snow",
defCon.titleCase(checkVersion(defCon.isUpgrade) instanceof Object),
"color:0",
defCon.titleCase(handlerInfo)
);
}
/* Version Detection with Cache and timeout * F9y4ng * 20210614 */
function fetchTimeout(url, time, { ...options } = {}) {
const controller = new AbortController();
const signal = controller.signal;
return new Promise((resolve, reject) => {
let t = setTimeout(() => {
controller.abort();
resolve(new Response("timeout", { status: 504, statusText: `Request timeout. (User-Defined: ${time}ms)` }));
}, time);
fetch(url, { signal: signal, ...options }).then(
res => {
clearTimeout(t);
resolve(res);
},
err => {
clearTimeout(t);
reject(err);
}
);
});
}
function fetchVersion(u) {
return new Promise((e, t) => {
fetchTimeout(u, 2000, {
method: "GET",
mode: "cors",
cache: "no-store",
credentials: "omit",
})
.then(e => {
debug("//-> %c%s %s", "color:green", e.ok, e.status);
if (!e.ok) {
throw Error(`${e.status} ${e.statusText}`);
}
return e.text();
})
.then(t => {
let n = defCon.curVersion;
let m = defCon.updateNote;
t.split(/[\r\n]+/).forEach(function (item) {
let key = item.match(/^(\/\/\s+@version\s+)(\S+)$/);
if (key) {
n = key[2];
}
let note = item.match(/^(\/\/\s+@note\s+)(.+)$/);
if (note) {
m = note[2];
}
});
e([compareVersion(defCon.curVersion, n), defCon.encrypt(n), defCon.encrypt(m), defCon.encrypt(u)]);
})
.catch(e => {
error("//-> %cfetchVersion:\n%c%s", "font-weight:bold", "font-weight:normal", e);
t();
});
});
}
function compareVersion(current, compare) {
let compare_array = compare.split(".");
let current_array = current.split(".");
let upgradeID = 0;
if (compare_array.length === current_array.length) {
for (let i = 0; i < compare_array.length; i++) {
if (parseInt(compare_array[i]) < parseInt(current_array[i])) {
upgradeID = 2;
break;
} else {
if (parseInt(compare_array[i]) === parseInt(current_array[i])) {
continue;
} else {
upgradeID = 1;
break;
}
}
}
} else {
upgradeID = 2;
}
return upgradeID;
}
async function checkVersion(s = false) {
let t, setResult, info;
const _configuration = await GMgetValue("_configuration_");
let useBing, VerDetAuto, checkUpdate, timeNumber, timeUnit, GoogleJump, _data;
if (!_configuration) {
useBing = 0;
VerDetAuto = true;
checkUpdate = true;
timeNumber = 4;
timeUnit = "h";
GoogleJump = false;
_data = {
useBing,
VerDetAuto,
checkUpdate,
timeNumber,
timeUnit,
GoogleJump,
};
console.warn("%c[GB-Warning]%c\nThis is your first visit, the Bing search button will not be inserted by default.", "font-weight:bold;color:salmon", "color:1");
// initialization
GMdeleteValue("_Check_Version_Expire_");
GMdeleteValue("_expire_time_");
GMdeleteValue("_is_Ver_Det_");
GMdeleteValue("_if_Use_Bing_");
GMsetValue("_configuration_", defCon.encrypt(JSON.stringify(_data)));
} else {
_data = JSON.parse(defCon.decrypt(_configuration));
useBing = _data.useBing;
VerDetAuto = _data.VerDetAuto;
checkUpdate = _data.checkUpdate;
timeNumber = _data.timeNumber;
timeUnit = _data.timeUnit;
GoogleJump = _data.GoogleJump;
}
setResult = checkUpdate ? Boolean(VerDetAuto) : false;
const _expire_time = String(timeNumber + timeUnit);
const _expire_time_ = /(?!^0)^[0-9]+[smhdw]$/i.test(_expire_time) ? _expire_time : "4h";
if (setResult) {
// load cache
const exp = await GMgetValue("_Check_Version_Expire_");
const cache = GMgetExpire("_Check_Version_Expire_", exp, _expire_time_);
// Checking the local cache to reduce server requests
if (!cache) {
// first: greasyfork
t = await fetchVersion(`https://greasyfork.org/scripts/12909/code/${defCon.randString(32)}.meta.js`).catch(async () => {
defCon.fetchResult = "GreasyFork - Failed to fetch";
error(defCon.fetchResult);
});
// second: github
if (defCon.fetchResult.includes("GreasyFork")) {
t = await fetchVersion(`https://raw.githubusercontent.com/F9y4ng/GreasyFork-Scripts/master/Google%20%26%20Baidu%20Switcher.meta.js`).catch(async () => {
defCon.fetchResult = "Github - Failed to fetch";
error(defCon.fetchResult);
});
}
// third: github.cdn
if (defCon.fetchResult.includes("Github")) {
t = await fetchVersion(`https://cdn.staticaly.com/gh/F9y4ng/GreasyFork-Scripts/master/Google%20%26%20Baidu%20Switcher.meta.js`).catch(async () => {
defCon.fetchResult = "GlobalCDN - Failed to fetch";
error(defCon.fetchResult);
});
}
// final: Jsdelivr points to gitee
if (defCon.fetchResult.includes("GlobalCDN")) {
t = await fetchVersion(`https://cdn.jsdelivr.net/gh/F9y4ng/GreasyFork-Scripts@master/Google%20%26%20Baidu%20Switcher.meta.js`).catch(async () => {
defCon.fetchResult = "Jsdelivr - Failed to fetch";
error(defCon.fetchResult);
});
}
// Set value with expire
if (t !== undefined) {
GMsetExpire("_Check_Version_Expire_", t);
debug("//-> %ccheckVersion: Loading Data from Server.", "background-color:darkorange;color:snow");
} else {
console.error(
"%c[GB-Update]\n%cSome unknown exceptions cause version detection failure, most likely by a network error. Please try again later.",
"font-weight:bold;color:red",
"font-weight:bold;color:darkred"
);
}
} else {
t = cache;
debug("//-> %ccheckVersion: Loading Data from Cache.", "background-color:green;color:snow");
}
// Resolution return data
if (typeof t !== "undefined") {
const lastestVersion = defCon.decrypt(t[1]);
defCon.isNoticed = Number(sessionStorage.getItem("nCount")) || 0;
defCon.isNeedUpdate = cache ? compareVersion(defCon.curVersion, lastestVersion) : t[0];
const updateNote = ((w = "") => {
if (defCon.decrypt(t[2])) {
defCon
.decrypt(t[2])
.split(/\\n/)
.forEach(function (item) {
w += `
${item}
`;
});
}
return w ? `
${w}
` : "";
})();
const updateUrl = defCon.decrypt(t[3]).replace("meta", "user");
const recheckURLs = new URL(
updateUrl
.replace("raw.githubusercontent.com", "github.com")
.replace("cdn.staticaly.com/gh", "github_cdn.com")
.replace("cdn.jsdelivr.net/gh", "gitee.com")
.replace("@", "/")
.replace("master", "blob/master")
.replace(/code\/[^/]+\.js/, "")
);
let sourceSite = defCon.titleCase(recheckURLs.hostname).split(".")[0];
sourceSite = sourceSite.replace("_cdn", ".CDN");
sourceSite = cache ? `${sourceSite} on Cache` : sourceSite;
const repo = cache
? `\nCache expire:${defCon.durationTime(defCon.restTime)}\nDetection: ${defCon.lastRuntime()}\n`
: `\nExpiration: ${_expire_time_}\nDetection: ${defCon.lastRuntime()}\n`;
switch (defCon.isNeedUpdate) {
case 2:
if (window.self === window.top) {
console.warn(
String(
`%c[GB-Update]%c\nWe found a new version, But %cthe latest version ` +
`%c${lastestVersion}%c is lower than your local version %c${defCon.curVersion}.%c\n\n` +
`Please confirm whether you need to upgrade your local script, and then you need to update it manually.\n` +
`${repo}(${sourceSite})`
),
"font-weight:bold;color:crimson",
"font-weight:bold;color:0",
"color:0",
"font-weight:bold;color:tomato",
"color:0",
"font-weight:bold;color:darkred",
"color:0"
);
}
if (defCon.isNoticed < 2 || s) {
setTimeout(function () {
GMnotification(
Notice.noticeHTML(
`