Skip to content

Commit 9ecece9

Browse files
committed
v6.7.0
Signed-off-by: Magic <magicoflolis@tuta.io>
1 parent 9d0e387 commit 9ecece9

19 files changed

+529
-186
lines changed

dist/magic-userjs.meta.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/magic-userjs.user.js

Lines changed: 82 additions & 74 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "https://github.com/magicoflolis/Userscript-Plus/issues"
1010
},
1111
"userJS": {
12-
"version": "6.6.2",
12+
"version": "6.7.0",
1313
"name": "Magic Userscript+ : Show Site All UserJS",
1414
"description": "Finds available userscripts for the current webpage.",
1515
"bugs": "https://github.com/magicoflolis/Userscript-Plus/issues",

src/UserJS/main.js

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// TODO: Add polish (pl)
2-
31
// #region Console
42
const dbg = (...msg) => {
53
const dt = new Date();
@@ -61,7 +59,8 @@ function safeSelf() {
6159
createElementNS: g.document.createElementNS.bind(g.document),
6260
createTextNode: g.document.createTextNode.bind(g.document),
6361
setTimeout: g.setTimeout,
64-
clearTimeout: g.clearTimeout
62+
clearTimeout: g.clearTimeout,
63+
trustedTypes: g.trustedTypes
6564
};
6665
userjs.safeSelf = safe;
6766
return safe;
@@ -581,9 +580,12 @@ const iconSVG = {
581580
}
582581
svgElem.setAttributeNS(null, k, v);
583582
}
584-
if (typeof iconSVG[type].html === 'string') {
585-
svgElem.innerHTML = iconSVG[type].html;
586-
}
583+
try {
584+
if (typeof iconSVG[type].html === 'string') {
585+
svgElem.innerHTML = iconSVG[type].html;
586+
}
587+
// eslint-disable-next-line no-unused-vars
588+
} catch (ex) { /* empty */ }
587589
if (container) {
588590
container.appendChild(svgElem);
589591
return svgElem;
@@ -726,7 +728,7 @@ const Network = {
726728
if (Number.isNaN(bytes)) return '0 Bytes';
727729
const k = 1024;
728730
const dm = decimals < 0 ? 0 : decimals;
729-
const i = Math.floor(Math.pow(bytes) / Math.log(k));
731+
const i = Math.floor(Math.log(bytes) / Math.log(k));
730732
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${Network.sizes[i]}`;
731733
},
732734
sizes: ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
@@ -843,6 +845,7 @@ const sleazyRedirect = () => {
843845
/\/\/([^.]+\.)?(greasyfork|sleazyfork)\.org/,
844846
'//$1' + otherSite + '.org'
845847
);
848+
info(`Redirecting to "${str}"`);
846849
if (isFN(winLocation.assign)) {
847850
winLocation.assign(str);
848851
} else {
@@ -958,7 +961,7 @@ class initContainer {
958961
*/
959962
async inject(callback, doc) {
960963
if (this.checkBlacklist(this.host)) {
961-
err('Blacklisted website');
964+
err(`Blacklisted "${this.host}"`);
962965
this.remove();
963966
return;
964967
}
@@ -1055,6 +1058,9 @@ class initContainer {
10551058
checkBlacklist(str) {
10561059
str = str || this.host;
10571060
let blacklisted = false;
1061+
if (/accounts*\.google\./.test(this.webpage.host)) {
1062+
blacklisted = true;
1063+
}
10581064
for (const b of normalizeTarget(cfg.blacklist)) {
10591065
if (typeof b === 'string') {
10601066
if (b.startsWith('userjs-')) {
@@ -1575,9 +1581,6 @@ function primaryFN() {
15751581
elem.remove();
15761582
}
15771583
}
1578-
if (container.oldBlacklist) {
1579-
delete container.oldBlacklist;
1580-
}
15811584
container.unsaved = true;
15821585
container.rebuild = true;
15831586
rebuildCfg();
@@ -1785,7 +1788,7 @@ function primaryFN() {
17851788

17861789
checkBlacklist(str) {
17871790
if (container.checkBlacklist(str)) {
1788-
this.showError('Blacklisted');
1791+
this.showError(`Blacklisted "${str}"`);
17891792
timeoutFrame();
17901793
return true;
17911794
}
@@ -2031,6 +2034,7 @@ function primaryFN() {
20312034
}
20322035
Object.assign(obj, {
20332036
code_data: code,
2037+
code_meta: {},
20342038
code_size: [Network.format(code.length)],
20352039
code_match: [],
20362040
code_grant: [],
@@ -2040,6 +2044,24 @@ function primaryFN() {
20402044
const afSet = new Set();
20412045
const meta = parse_meta(code);
20422046
const applies_to_names = calculate_applies_to_names(code);
2047+
2048+
if (translate) {
2049+
for (const lng of language.cache) {
2050+
if (meta[`name:${lng}`]) {
2051+
Object.assign(obj, {
2052+
name: meta[`name:${lng}`],
2053+
translated: true
2054+
});
2055+
}
2056+
if (meta[`description:${lng}`]) {
2057+
Object.assign(obj, {
2058+
description: meta[`description:${lng}`],
2059+
translated: true
2060+
});
2061+
}
2062+
}
2063+
}
2064+
20432065
for (const [key, value] of Object.entries(meta)) {
20442066
if (/grant/.test(key)) {
20452067
for (const v of normalizeTarget(value, false)) {
@@ -2058,32 +2080,11 @@ function primaryFN() {
20582080
}
20592081
}
20602082
Object.assign(obj, {
2083+
code_meta: meta,
20612084
code_match: applies_to_names,
20622085
code_grant: [...grantSet],
20632086
antifeatures: [...afSet]
20642087
});
2065-
if (translate) {
2066-
const headers = code.match(/\/\/\s*@[\w][\s\S]+/g);
2067-
if (isNull(headers)) {
2068-
return code;
2069-
}
2070-
for (const lng of language.cache) {
2071-
const findName = new RegExp(`//\\s*@name:${lng}\\s*(.*)`, 'gi').exec(headers[0]);
2072-
const findDesc = new RegExp(`//\\s*@description:${lng}\\s*(.*)`, 'gi').exec(headers[0]);
2073-
if (!isNull(findName)) {
2074-
Object.assign(obj, {
2075-
name: findName[1],
2076-
translated: true
2077-
});
2078-
}
2079-
if (!isNull(findDesc)) {
2080-
Object.assign(obj, {
2081-
description: findDesc[1],
2082-
translated: true
2083-
});
2084-
}
2085-
}
2086-
}
20872088
return code;
20882089
};
20892090
const template = {
@@ -2291,6 +2292,12 @@ function primaryFN() {
22912292
});
22922293
if (engine) {
22932294
tr.dataset.engine = engine;
2295+
// if (engine.includes('fork')) {
2296+
// fdaily.dataset.command = 'open-tab';
2297+
// fdaily.dataset.webpage = `${ujs.url}/stats`;
2298+
// fupdated.dataset.command = 'open-tab';
2299+
// fupdated.dataset.webpage = `${ujs.url}/versions`;
2300+
// }
22942301
if (!engine.includes('fork') && cfg.recommend.others && goodUserJS.includes(ujs.url)) {
22952302
tr.dataset.good = 'upsell';
22962303
}
@@ -2316,7 +2323,7 @@ function primaryFN() {
23162323
eframe.append(scriptInstall);
23172324
ratings.append(fratings, fgood, fok, fbad);
23182325
jsInfo.append(ftotal, ratings, fver, fcreated);
2319-
mkList('Size', {
2326+
mkList(i18n$('code_size'), {
23202327
list: ujs.code_size,
23212328
type: 'size',
23222329
root: jsInfo
@@ -2358,10 +2365,6 @@ function primaryFN() {
23582365
if (isEmpty(host)) {
23592366
host = container.host;
23602367
}
2361-
if (container.oldBlacklist) {
2362-
MUJS.makeError({ message: i18n$('legacy'), cause: 'Blacklist outdated', notify: true });
2363-
return;
2364-
}
23652368
if (MUJS.checkBlacklist(host)) {
23662369
return;
23672370
}
@@ -2409,6 +2412,7 @@ function primaryFN() {
24092412
}
24102413
createjs(ujs, engine);
24112414
};
2415+
const arr = [];
24122416
for (const engine of engines) {
24132417
const cEngine = cache[`${engine.name}`];
24142418
if (!isEmpty(cEngine)) {
@@ -2418,16 +2422,24 @@ function primaryFN() {
24182422
MUJS.updateCounter(cEngine.length, engine);
24192423
continue;
24202424
}
2425+
/**
2426+
* @param { import("../typings/UserJS.d.ts").GSFork } dataQ
2427+
*/
24212428
const forkFN = async (dataQ) => {
24222429
if (!dataQ) {
2423-
MUJS.showError('Invalid data received from the server, TODO fix this');
2430+
MUJS.showError('Invalid data received from the server, check internet connection');
24242431
return;
24252432
}
2426-
const data = dataQ.query;
2427-
if (!Array.isArray(data)) {
2433+
2434+
const data = (Array.isArray(dataQ.query) ? dataQ.query : []).filter((d) => !d.deleted);
2435+
if (isBlank(data)) {
24282436
return;
24292437
}
24302438
const hideData = [];
2439+
/**
2440+
* @param {import("../typings/UserJS.d.ts").GSForkQuery} d
2441+
* @returns {boolean}
2442+
*/
24312443
const inUserLanguage = (d) => {
24322444
const dlocal = d.locale.split('-')[0] ?? d.locale;
24332445
if (language.cache.includes(dlocal)) {
@@ -2437,9 +2449,6 @@ function primaryFN() {
24372449
return false;
24382450
};
24392451
const filterLang = data.filter((d) => {
2440-
if (d.deleted) {
2441-
return false;
2442-
}
24432452
if (cfg.filterlang && !inUserLanguage(d)) {
24442453
return false;
24452454
}
@@ -2448,7 +2457,7 @@ function primaryFN() {
24482457
let finalList = filterLang;
24492458
const hds = [];
24502459
for (const ujs of hideData) {
2451-
await reqCode(ujs);
2460+
await reqCode(ujs, true);
24522461
if (ujs.translated) {
24532462
hds.push(ujs);
24542463
}
@@ -2543,16 +2552,17 @@ function primaryFN() {
25432552
MUJS.showError(ex);
25442553
}
25452554
};
2555+
let netFN;
25462556
if (engine.name.includes('fork')) {
2547-
Network.req(`${engine.url}/scripts/by-site/${host}.json`)
2557+
netFN = Network.req(`${engine.url}/scripts/by-site/${host}.json`)
25482558
.then(forkFN)
25492559
.catch(MUJS.showError);
25502560
} else if (/github/gi.test(engine.name)) {
25512561
if (isEmpty(engine.token)) {
25522562
MUJS.showError(`"${engine.name}" requires a token to use`);
25532563
continue;
25542564
}
2555-
Network.req(
2565+
netFN = Network.req(
25562566
`${engine.url}"// ==UserScript=="+${host}+ "// ==/UserScript=="+in:file+language:js&per_page=30`,
25572567
'GET',
25582568
'json',
@@ -2585,15 +2595,22 @@ function primaryFN() {
25852595
})
25862596
.catch(MUJS.showError);
25872597
} else {
2588-
Network.req(`${engine.url}${host}`, 'GET', 'document')
2598+
netFN = Network.req(`${engine.url}${host}`, 'GET', 'document')
25892599
.then(customFN)
25902600
.catch((error) => {
25912601
MUJS.showError(`Engine: "${engine.name}"`, error);
25922602
});
25932603
}
2604+
if (netFN) {
2605+
arr.push(netFN);
2606+
}
25942607
}
25952608
urlBar.placeholder = i18n$('search_placeholder');
25962609
urlBar.value = '';
2610+
Promise.allSettled(arr).then(() => {
2611+
tabhead.rows[0].cells[2].dispatchEvent(new MouseEvent('click'));
2612+
tabhead.rows[0].cells[2].dispatchEvent(new MouseEvent('click'));
2613+
});
25972614
} catch (ex) {
25982615
MUJS.showError(ex);
25992616
}
@@ -2955,11 +2972,9 @@ function primaryFN() {
29552972
dom.cl.add(th, 'mujs-pointer');
29562973
ael(th, 'click', () => {
29572974
/** [Stack Overflow Reference](https://stackoverflow.com/questions/14267781/sorting-html-table-with-javascript/53880407#53880407) */
2958-
const table = th.closest('table');
2959-
const tbody = table.querySelector('tbody');
2960-
Array.from(tbody.querySelectorAll('tr'))
2975+
Array.from(tabbody.querySelectorAll('tr'))
29612976
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), (this.asc = !this.asc)))
2962-
.forEach((tr) => tbody.appendChild(tr));
2977+
.forEach((tr) => tabbody.appendChild(tr));
29632978
});
29642979
}
29652980
makecfg();
@@ -2987,24 +3002,8 @@ const loadDOM = (onDomReady) => {
29873002
once: true
29883003
});
29893004
};
2990-
// /**
2991-
// * @type { import("../typings/UserJS.d.ts").setObj }
2992-
// */
2993-
// const setObj = (objA = {}, objB = {}) => {
2994-
// objA = objA || {};
2995-
// objB = objB || {};
2996-
// for (const [key, value] of Object.entries(objA)) {
2997-
// if (!hasOwn(objB, key)) {
2998-
// objB[key] = value;
2999-
// } else if (typeof value === 'object') {
3000-
// setObj(value, objB[key]);
3001-
// }
3002-
// }
3003-
// return objB;
3004-
// };
30053005
const init = async () => {
30063006
const stored = await StorageSystem.getValue('Config', defcfg);
3007-
// cfg = setObj(defcfg, stored);
30083007
cfg = {
30093008
...defcfg,
30103009
...stored
@@ -3013,12 +3012,15 @@ const init = async () => {
30133012
loadDOM((doc) => {
30143013
try {
30153014
if (window.location === null) {
3016-
err('"window.location" is null, reload the webpage or use a different one');
3017-
return;
3015+
throw new Error ('"window.location" is null, reload the webpage or use a different one');
30183016
}
30193017
if (doc === null) {
3020-
err('"doc" is null, reload the webpage or use a different one');
3021-
return;
3018+
throw new Error ('"doc" is null, reload the webpage or use a different one');
3019+
}
3020+
if (window.trustedTypes && window.trustedTypes.createPolicy) {
3021+
window.trustedTypes.createPolicy('default', {
3022+
createHTML: (string) => string
3023+
});
30223024
}
30233025
sleazyRedirect();
30243026
container.inject(primaryFN, doc);

src/_locales/ar/messages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
"userjs_description": {
1818
"message": "يبحث عن نصوص المستخدمين المتاحة لصفحة الويب الحالية."
1919
},
20-
"legacy": {
21-
"message": "يرجى إعادة ضبط التكوين الخاص بك!"
22-
},
2320
"createdby": {
2421
"message": "انشأ من قبل"
2522
},
@@ -130,5 +127,8 @@
130127
},
131128
"import_theme": {
132129
"message": "استيراد النسق"
130+
},
131+
"code_size": {
132+
"message": "حجم الرمز"
133133
}
134134
}

0 commit comments

Comments
 (0)