Greasemonkey: es6ify the greasemonkey wrapper js.
Because backwards compatibility sucks I guess.
This commit is contained in:
parent
92b48e77c7
commit
8a5b42ffbd
@ -1,11 +1,11 @@
|
|||||||
(function () {
|
(function () {
|
||||||
var _qute_script_id = "__gm_"+{{ scriptName | tojson }};
|
const _qute_script_id = "__gm_"+{{ scriptName | tojson }};
|
||||||
|
|
||||||
function GM_log(text) {
|
function GM_log(text) {
|
||||||
console.log(text);
|
console.log(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
var GM_info = {
|
const GM_info = {
|
||||||
'script': {{ scriptInfo }},
|
'script': {{ scriptInfo }},
|
||||||
'scriptMetaStr': {{ scriptMeta | tojson }},
|
'scriptMetaStr': {{ scriptMeta | tojson }},
|
||||||
'scriptWillUpdate': false,
|
'scriptWillUpdate': false,
|
||||||
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
function checkKey(key, funcName) {
|
function checkKey(key, funcName) {
|
||||||
if (typeof key !== "string") {
|
if (typeof key !== "string") {
|
||||||
throw new Error(funcName+" requires the first parameter to be of type string, not '"+typeof key+"'");
|
throw new Error(`${funcName} requires the first parameter to be of type string, not '${typeof key}'`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@
|
|||||||
if (typeof value !== "string" &&
|
if (typeof value !== "string" &&
|
||||||
typeof value !== "number" &&
|
typeof value !== "number" &&
|
||||||
typeof value !== "boolean") {
|
typeof value !== "boolean") {
|
||||||
throw new Error("GM_setValue requires the second parameter to be of type string, number or boolean, not '"+typeof value+"'");
|
throw new Error(`GM_setValue requires the second parameter to be of type string, number or boolean, not '${typeof value}'`);
|
||||||
}
|
}
|
||||||
localStorage.setItem(_qute_script_id + key, value);
|
localStorage.setItem(_qute_script_id + key, value);
|
||||||
}
|
}
|
||||||
@ -40,8 +40,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function GM_listValues() {
|
function GM_listValues() {
|
||||||
var keys = [];
|
let keys = [];
|
||||||
for (var i = 0; i < localStorage.length; i++) {
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
if (localStorage.key(i).startsWith(_qute_script_id)) {
|
if (localStorage.key(i).startsWith(_qute_script_id)) {
|
||||||
keys.push(localStorage.key(i).slice(_qute_script_id.length));
|
keys.push(localStorage.key(i).slice(_qute_script_id.length));
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build XMLHttpRequest object
|
// build XMLHttpRequest object
|
||||||
var oXhr = new XMLHttpRequest();
|
let oXhr = new XMLHttpRequest();
|
||||||
// run it
|
// run it
|
||||||
if ("onreadystatechange" in details) {
|
if ("onreadystatechange" in details) {
|
||||||
oXhr.onreadystatechange = function () {
|
oXhr.onreadystatechange = function () {
|
||||||
@ -80,7 +80,7 @@
|
|||||||
oXhr.open(details.method, details.url, true);
|
oXhr.open(details.method, details.url, true);
|
||||||
|
|
||||||
if ("headers" in details) {
|
if ("headers" in details) {
|
||||||
for (var header in details.headers) {
|
for (let header in details.headers) {
|
||||||
oXhr.setRequestHeader(header, details.headers[header]);
|
oXhr.setRequestHeader(header, details.headers[header]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,11 +93,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function GM_addStyle(/* String */ styles) {
|
function GM_addStyle(/* String */ styles) {
|
||||||
var oStyle = document.createElement("style");
|
let oStyle = document.createElement("style");
|
||||||
oStyle.setAttribute("type", "text/css");
|
oStyle.setAttribute("type", "text/css");
|
||||||
oStyle.appendChild(document.createTextNode(styles));
|
oStyle.appendChild(document.createTextNode(styles));
|
||||||
|
|
||||||
var head = document.getElementsByTagName("head")[0];
|
let head = document.getElementsByTagName("head")[0];
|
||||||
if (head === undefined) {
|
if (head === undefined) {
|
||||||
document.onreadystatechange = function () {
|
document.onreadystatechange = function () {
|
||||||
if (document.readyState == "interactive") {
|
if (document.readyState == "interactive") {
|
||||||
@ -110,7 +110,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var unsafeWindow = window;
|
const unsafeWindow = window;
|
||||||
|
|
||||||
//====== The actual user script source ======//
|
//====== The actual user script source ======//
|
||||||
{{ scriptSource }}
|
{{ scriptSource }}
|
||||||
|
Loading…
Reference in New Issue
Block a user