Skip to content

Commit c3e4951

Browse files
authored
v2.51
1 parent 8ae03cd commit c3e4951

6 files changed

Lines changed: 480 additions & 452 deletions

File tree

content/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218

219219
async openInTab(url, open_in_background) {
220220
// TM|VM compatibility
221-
const active = !open_in_background || typeof open_in_background === 'boolean' ?
221+
const active = !open_in_background || typeof open_in_background === 'boolean' ?
222222
!open_in_background : !!open_in_background?.active;
223223
// Error: Return value not accessible to the userScript
224224
// resolve -> tab object | reject -> undefined

content/app.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let pref = {
1414
};
1515
// ----------------- /Default Preference -------------------
1616

17+
// ----------------- App -----------------------------------
1718
class App {
1819

1920
// ----------------- User Preference -----------------------
@@ -73,19 +74,19 @@ class App {
7374
static export() {
7475
const data = JSON.stringify(pref, null, 2);
7576
const filename = `${browser.i18n.getMessage('extensionName')}_${new Date().toISOString().substring(0, 10)}.json`;
76-
App.saveFile(data, filename);
77+
App.saveFile({data, filename});
7778
}
7879

79-
static saveFile(data, filename, saveAs = true) {
80-
if (!browser.downloads) { // Android
80+
static saveFile({data, filename, saveAs = true, type = 'text/plain'}) {
81+
if (!browser.downloads) {
8182
const a = document.createElement('a');
8283
a.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(data);
8384
a.setAttribute('download', filename);
8485
a.dispatchEvent(new MouseEvent('click'));
8586
return;
8687
}
8788

88-
const blob = new Blob([data], {type: 'text/plain;charset=utf-8'});
89+
const blob = new Blob([data], {type});
8990
browser.downloads.download({
9091
url: URL.createObjectURL(blob),
9192
filename,
@@ -100,7 +101,7 @@ class App {
100101
this.i18nSet();
101102

102103
document.body.classList.toggle('dark', localStorage.getItem('dark') === 'true'); // light/dark theme
103-
document.body.style.opacity = 1; // show after i18n
104+
document.body.style.opacity = 1; // show after i18n
104105
}
105106

106107
static i18nSet(target = document) {
@@ -145,6 +146,7 @@ class App {
145146
}
146147
}
147148
App.android = navigator.userAgent.includes('Android');
149+
// ----------------- /App ----------------------------------
148150

149151
// ----------------- Parse Metadata Block ------------------
150152
class Meta { // bg options
@@ -262,7 +264,7 @@ class Meta { // bg options
262264
// --- add @require
263265
case 'require':
264266
const url = value.toLowerCase().replace(/^(http:)?\/\//, 'https://'); // change starting http:// & Protocol-relative URL //
265-
const [protocol, host] = url.split(/:?\/+/);
267+
const [protocol, host] = url.split(/[:/]+/);
266268
const cdnHosts = ['ajax.aspnetcdn.com', 'ajax.googleapis.com', 'apps.bdimg.com', 'cdn.bootcdn.net',
267269
'cdn.bootcss.com', 'cdn.jsdelivr.net', 'cdn.staticfile.org', 'cdnjs.cloudflare.com',
268270
'code.jquery.com', 'lib.baomitu.com', 'libs.baidu.com', 'pagecdn.io', 'unpkg.com'];
@@ -371,7 +373,7 @@ class Meta { // bg options
371373
};
372374

373375
const r = rule.split(/\s*[\s()'",]+\s*/); // split into pairs
374-
for (let i = 0, len = r.length; i < len; i+=2) {
376+
for (let i = 0; i < r.length; i+=2) {
375377
if(!r[i+1]) { break; }
376378
const func = r[i];
377379
const value = r[i+1];
@@ -676,29 +678,21 @@ class RemoteUpdate { // bg options
676678
return version && this.higherVersion(version[1], item.version);
677679
}
678680

679-
getScript(item) { // here bg 1
681+
getScript(item) { // here & bg
680682
fetch(item.updateURL)
681683
.then(response => response.text())
682684
.then(text => this.callback(text, item.name, item.updateURL))
683685
.catch(error => App.log(item.name, `getScript ${item.updateURL}${error.message}`, 'error'));
684686
}
685687

686-
higherVersion(a, b) { // here bg 1 opt 1
687-
a = a.split('.').map(n => parseInt(n));
688-
b = b.split('.').map(n => parseInt(n));
689-
690-
for (let i = 0, len = Math.max(a.length, b.length); i < len; i++) {
691-
if (!a[i]) { return false; }
692-
else if ((a[i] && !b[i]) || a[i] > b[i]) { return true; }
693-
else if (a[i] < b[i]) { return false; }
694-
}
695-
return false;
688+
higherVersion(a, b) { // here & bg & opt
689+
return a.localeCompare(b, undefined, {numeric: true, sensitivity: 'base'}) > 0;
696690
}
697691
}
698692
// ----------------- /Remote Update ------------------------
699693

700694
// ----------------- Match Pattern Check -------------------
701-
class CheckMatches { // used in bg & popup
695+
class CheckMatches { // bg & popup
702696

703697
static async process(tab, bg) {
704698
const supported = this.supported(tab.url);

0 commit comments

Comments
 (0)