Skip to content

Commit 6d240a7

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

File tree

5 files changed

+231
-25
lines changed

5 files changed

+231
-25
lines changed

dist/magic-userjs.meta.js

Lines changed: 1 addition & 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: 74 additions & 10 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.7.0",
12+
"version": "6.7.1",
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: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: add translations to "Install as user style?"
2+
13
// #region Console
24
const dbg = (...msg) => {
35
const dt = new Date();
@@ -508,6 +510,7 @@ class Memorize {
508510
}
509511
}
510512
const memory = new Memorize();
513+
//#region Icon SVGs
511514
const iconSVG = {
512515
cfg: {
513516
viewBox: '0 0 24 24',
@@ -571,6 +574,11 @@ const iconSVG = {
571574
stroke: 'currentColor',
572575
html: '<g stroke-width="0"/><g stroke-linecap="round" stroke-linejoin="round"/><g><path d="M 23.6641 52.3985 C 26.6407 55.375 29.3594 55.3516 32.3126 52.3985 L 35.9219 48.8125 C 36.2969 48.4610 36.6250 48.3203 37.1172 48.3203 L 42.1797 48.3203 C 46.3749 48.3203 48.3204 46.3985 48.3204 42.1797 L 48.3204 37.1172 C 48.3204 36.625 48.4610 36.2969 48.8124 35.9219 L 52.3749 32.3125 C 55.3749 29.3594 55.3514 26.6407 52.3749 23.6641 L 48.8124 20.0547 C 48.4610 19.7031 48.3204 19.3516 48.3204 18.8829 L 48.3204 13.7969 C 48.3204 9.625 46.3985 7.6563 42.1797 7.6563 L 37.1172 7.6563 C 36.6250 7.6563 36.2969 7.5391 35.9219 7.1875 L 32.3126 3.6016 C 29.3594 .6250 26.6407 .6485 23.6641 3.6016 L 20.0547 7.1875 C 19.7032 7.5391 19.3516 7.6563 18.8828 7.6563 L 13.7969 7.6563 C 9.6016 7.6563 7.6563 9.5782 7.6563 13.7969 L 7.6563 18.8829 C 7.6563 19.3516 7.5391 19.7031 7.1876 20.0547 L 3.6016 23.6641 C .6251 26.6407 .6485 29.3594 3.6016 32.3125 L 7.1876 35.9219 C 7.5391 36.2969 7.6563 36.625 7.6563 37.1172 L 7.6563 42.1797 C 7.6563 46.3750 9.6016 48.3203 13.7969 48.3203 L 18.8828 48.3203 C 19.3516 48.3203 19.7032 48.4610 20.0547 48.8125 Z M 26.2891 49.7734 L 21.8828 45.3438 C 21.3672 44.8047 20.8282 44.5938 20.1016 44.5938 L 13.7969 44.5938 C 11.7110 44.5938 11.3828 44.2656 11.3828 42.1797 L 11.3828 35.875 C 11.3828 35.1719 11.1719 34.6329 10.6563 34.1172 L 6.2266 29.7109 C 4.7501 28.2109 4.7501 27.7891 6.2266 26.2891 L 10.6563 21.8829 C 11.1719 21.3672 11.3828 20.8282 11.3828 20.1016 L 11.3828 13.7969 C 11.3828 11.6875 11.6876 11.3829 13.7969 11.3829 L 20.1016 11.3829 C 20.8282 11.3829 21.3672 11.1953 21.8828 10.6563 L 26.2891 6.2266 C 27.7891 4.7500 28.2110 4.7500 29.7110 6.2266 L 34.1172 10.6563 C 34.6328 11.1953 35.1719 11.3829 35.8750 11.3829 L 42.1797 11.3829 C 44.2657 11.3829 44.5938 11.7109 44.5938 13.7969 L 44.5938 20.1016 C 44.5938 20.8282 44.8282 21.3672 45.3439 21.8829 L 49.7733 26.2891 C 51.2498 27.7891 51.2498 28.2109 49.7733 29.7109 L 45.3439 34.1172 C 44.8282 34.6329 44.5938 35.1719 44.5938 35.875 L 44.5938 42.1797 C 44.5938 44.2656 44.2657 44.5938 42.1797 44.5938 L 35.8750 44.5938 C 35.1719 44.5938 34.6328 44.8047 34.1172 45.3438 L 29.7110 49.7734 C 28.2110 51.2500 27.7891 51.2500 26.2891 49.7734 Z M 24.3438 39.2266 C 25.0235 39.2266 25.5391 38.9453 25.8907 38.5234 L 38.8985 20.3360 C 39.1563 19.9609 39.2969 19.5391 39.2969 19.1407 C 39.2969 18.1094 38.5001 17.2891 37.4219 17.2891 C 36.6485 17.2891 36.2266 17.5469 35.7579 18.2266 L 24.2735 34.3985 L 18.3438 27.8594 C 17.9454 27.4141 17.5001 27.2266 16.9141 27.2266 C 15.7657 27.2266 14.9454 28.0000 14.9454 29.0782 C 14.9454 29.5469 15.1094 29.9922 15.4376 30.3203 L 22.8907 38.6172 C 23.2423 38.9922 23.6876 39.2266 24.3438 39.2266 Z"/></g>'
573576
},
577+
refresh: {
578+
viewBox: '0 0 1024 1024',
579+
fill: 'currentColor',
580+
html: '<path d="M981.314663 554.296783a681.276879 681.276879 0 0 1-46.986468 152.746388q-105.706098 230.734238-360.983096 242.19829a593.06288 593.06288 0 0 1-228.689008-33.853939v-1.022615l-31.808709 79.979258a55.759429 55.759429 0 0 1-20.506122 22.551352 40.043451 40.043451 0 0 1-21.04434 5.382184 51.076928 51.076928 0 0 1-19.483507-5.382184 95.210839 95.210839 0 0 1-13.347817-7.158305 52.314831 52.314831 0 0 1-5.382184-4.628679L71.671707 731.908862a57.427906 57.427906 0 0 1-7.158305-21.528737 46.932646 46.932646 0 0 1 1.022615-17.438277 35.952991 35.952991 0 0 1 7.158305-13.347816 74.435608 74.435608 0 0 1 10.279972-10.279972 60.495751 60.495751 0 0 1 11.248765-7.373593 50.431066 50.431066 0 0 1 8.18092-3.606063 6.189512 6.189512 0 0 0 3.067845-1.776121l281.003839-74.866183a91.497132 91.497132 0 0 1 35.899168-2.583448 122.337047 122.337047 0 0 1 22.174599 6.404799 21.528737 21.528737 0 0 1 12.325202 12.325202 76.157907 76.157907 0 0 1 4.628679 14.854829 47.63233 47.63233 0 0 1 0 14.370431 55.167388 55.167388 0 0 1-2.04523 10.764369 10.764368 10.764368 0 0 0-1.022615 3.606063l-32.831324 79.979258a677.50935 677.50935 0 0 0 164.264262 39.505232q77.395809 7.696523 131.809692-3.606063a358.507291 358.507291 0 0 0 101.023598-36.921784 381.27393 381.27393 0 0 0 73.951211-50.753997 352.64071 352.64071 0 0 0 48.708767-55.382676 410.391547 410.391547 0 0 0 26.910921-41.550462c3.767529-7.481236 6.673908-13.616926 8.719139-18.460892zM40.885614 449.667121a685.69027 685.69027 0 0 1 63.563595-176.427998q118.0313-212.273346 374.330913-207.160271a571.803252 571.803252 0 0 1 207.160271 39.989629l33.853939-78.956643A75.619688 75.619688 0 0 1 735.187378 9.189165a37.67529 37.67529 0 0 1 15.393047-8.234742 42.303968 42.303968 0 0 1 14.854829-0.538219 47.578509 47.578509 0 0 1 13.347817 3.606064 102.907362 102.907362 0 0 1 11.302586 6.13569 49.569917 49.569917 0 0 1 6.673909 4.628678l3.067845 3.067845 154.84544 276.913379a81.970666 81.970666 0 0 1 6.13569 22.712817 46.986468 46.986468 0 0 1-1.022615 17.438277 32.293105 32.293105 0 0 1-7.696523 13.347817 69.322533 69.322533 0 0 1-10.764369 9.741753 92.142994 92.142994 0 0 1-11.302587 6.673909l-8.18092 4.09046a7.104483 7.104483 0 0 1-3.067845 1.022615l-283.049068 67.546412a112.003254 112.003254 0 0 1-46.125319-1.022615c-11.571696-3.390776-19.160576-8.019454-22.551352-13.832214a41.173709 41.173709 0 0 1-5.382184-21.04434 97.256069 97.256069 0 0 1 1.291724-17.438277 24.381295 24.381295 0 0 1 3.067845-8.234742L600.632773 296.81309a663.730958 663.730958 0 0 0-164.102797-43.057474q-77.987849-9.203535-131.809692 0a348.227319 348.227319 0 0 0-101.292707 33.853938 368.571976 368.571976 0 0 0-75.350579 49.246986 383.31916 383.31916 0 0 0-50.269601 54.360061 408.507783 408.507783 0 0 0-28.740863 41.012244A113.025869 113.025869 0 0 0 40.885614 449.667121z m0 0" fill="#ffffff" p-id="2275"></path>'
581+
},
574582
load(type, container) {
575583
const safe = safeSelf();
576584
const svgElem = safe.createElementNS('http://www.w3.org/2000/svg', 'svg');
@@ -584,15 +592,18 @@ const iconSVG = {
584592
if (typeof iconSVG[type].html === 'string') {
585593
svgElem.innerHTML = iconSVG[type].html;
586594
}
587-
// eslint-disable-next-line no-unused-vars
588-
} catch (ex) { /* empty */ }
595+
// eslint-disable-next-line no-unused-vars
596+
} catch (ex) {
597+
/* empty */
598+
}
589599
if (container) {
590600
container.appendChild(svgElem);
591601
return svgElem;
592602
}
593603
return svgElem.outerHTML;
594604
}
595605
};
606+
//#endregion
596607
/**
597608
* @type { import("../typings/UserJS.d.ts").StorageSystem }
598609
*/
@@ -1159,6 +1170,7 @@ function primaryFN() {
11591170
textContent: '0'
11601171
});
11611172
const rateContainer = make('mujs-column', 'rate-container');
1173+
const promptElem = make('mujs-row', 'mujs-prompt');
11621174
const footer = make('mujs-row', 'mujs-footer');
11631175
const tabbody = make('tbody');
11641176
const toolbar = make('mujs-toolbar');
@@ -1270,7 +1282,7 @@ function primaryFN() {
12701282
urlContainer.append(urlBar);
12711283
header.append(urlContainer, rateContainer, countframe, btnframe);
12721284
tbody.append(table, cfgpage);
1273-
main.append(toolbar, header, tbody, footer);
1285+
main.append(toolbar, header, tbody, footer, promptElem);
12741286
mainframe.append(mainbtn);
12751287
exBtn.append(importCFG, importTheme, exportCFG, exportTheme);
12761288
header.append(exBtn);
@@ -1489,16 +1501,31 @@ function primaryFN() {
14891501
if (!target) {
14901502
return;
14911503
}
1492-
const dataset = target.dataset;
1493-
const cmd = dataset.command;
1504+
const prmpt = /prompt-/.test(target.dataset.command);
1505+
let dataset = target.dataset;
1506+
let cmd = dataset.command;
1507+
let prmptChoice = false;
1508+
if (prmpt) {
1509+
dataset = target.parentElement.dataset;
1510+
cmd = dataset.command;
1511+
prmptChoice = /confirm/.test(target.dataset.command);
1512+
target.parentElement.parentElement.remove();
1513+
}
14941514
if (cmd === 'install-script' && dataset.userjs) {
1515+
let installCode = dataset.userjs;
1516+
if (!prmpt && dataset.userjs.endsWith('.user.css')) {
1517+
MUJS.makePrompt('Install as user style?', dataset);
1518+
return;
1519+
} else if (prmpt !== prmptChoice) {
1520+
installCode = dataset.userjs.replace(/\.user\.css$/, '.user.js');
1521+
};
14951522
const dlBtn = make('a', '', {
14961523
onclick(evt) {
14971524
evt.preventDefault();
14981525
doInstallProcess(evt.target);
14991526
}
15001527
});
1501-
dlBtn.href = dataset.userjs;
1528+
dlBtn.href = installCode;
15021529
dlBtn.click();
15031530
} else if (cmd === 'open-tab' && dataset.webpage) {
15041531
if (isGM) {
@@ -1813,6 +1840,43 @@ function primaryFN() {
18131840
dom.text(mainbtn, container.counters.total);
18141841
}
18151842

1843+
makePrompt(txt, dataset = {}, usePrompt = true) {
1844+
if (qs('.prompt', promptElem)) {
1845+
for (const elem of qsA('.prompt', promptElem)) {
1846+
if (elem.dataset.prompt) {
1847+
elem.remove();
1848+
}
1849+
}
1850+
}
1851+
const el = make('mu-js', 'prompt', {
1852+
dataset: {
1853+
prompt: txt
1854+
}
1855+
});
1856+
const elHead = make('mu-js', 'prompt-head', {
1857+
innerHTML: `${iconSVG.load('refresh')} ${txt}`
1858+
});
1859+
el.append(elHead);
1860+
if (usePrompt) {
1861+
const elPrompt = make('mu-js', 'prompt-body', { dataset });
1862+
const elYes = make('mujs-btn', 'prompt-confirm', {
1863+
innerHTML: 'Confirm',
1864+
dataset: {
1865+
command: 'prompt-confirm'
1866+
}
1867+
});
1868+
const elNo = make('mujs-btn', 'prompt-deny', {
1869+
innerHTML: 'Deny',
1870+
dataset: {
1871+
command: 'prompt-deny'
1872+
}
1873+
});
1874+
elPrompt.append(elYes, elNo);
1875+
el.append(elPrompt);
1876+
}
1877+
promptElem.append(el);
1878+
}
1879+
18161880
makeError(...ex) {
18171881
const safe = safeSelf();
18181882
const error = make('mu-js', 'error');
@@ -3012,10 +3076,10 @@ const init = async () => {
30123076
loadDOM((doc) => {
30133077
try {
30143078
if (window.location === null) {
3015-
throw new Error ('"window.location" is null, reload the webpage or use a different one');
3079+
throw new Error('"window.location" is null, reload the webpage or use a different one');
30163080
}
30173081
if (doc === null) {
3018-
throw new Error ('"doc" is null, reload the webpage or use a different one');
3082+
throw new Error('"doc" is null, reload the webpage or use a different one');
30193083
}
30203084
if (window.trustedTypes && window.trustedTypes.createPolicy) {
30213085
window.trustedTypes.createPolicy('default', {

src/sass/_main.scss

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,15 @@ mujs-column {
119119
&[data-counter="greasyfork"] {
120120
background: var(--mujs-gf-color, hsl(204, 100%, 40%));
121121
}
122+
122123
&[data-counter="sleazyfork"] {
123124
background: var(--mujs-sf-color, hsl(12, 86%, 50%));
124125
}
126+
125127
&[data-counter="github"] {
126128
background: hsla(213, 13%, 16%);
127129
}
130+
128131
&[data-counter="openuserjs"] {
129132
background: hsla(12, 86%, 50%, 0.568);
130133
}
@@ -184,7 +187,7 @@ mujs-main {
184187
flex-direction: column !important;
185188
}
186189

187-
> * {
190+
>* {
188191
width: 100%;
189192
width: -moz-available;
190193
width: -webkit-fill-available;
@@ -195,15 +198,18 @@ mujs-main {
195198
padding: .5em;
196199
display: flex;
197200
place-content: space-between;
201+
198202
mujs-tabs {
199203
overflow: hidden;
200204
order: 0;
201205
}
206+
202207
mujs-column {
203208
flex-flow: row nowrap;
204209
order: 999999999999;
205210
}
206-
> * {
211+
212+
>* {
207213
width: -webkit-fit-content;
208214
width: -moz-fit-content;
209215
width: fit-content;
@@ -322,7 +328,7 @@ mujs-main {
322328
text-align: center;
323329
border-radius: 16px;
324330

325-
> * {
331+
>* {
326332
min-height: 50px;
327333
}
328334

@@ -336,6 +342,60 @@ mujs-main {
336342
}
337343
}
338344
}
345+
346+
.mujs-prompt {
347+
align-items: center;
348+
justify-content: center;
349+
350+
svg {
351+
width: 14px;
352+
height: 14px;
353+
background: transparent;
354+
}
355+
356+
>.prompt {
357+
position: absolute;
358+
background: var(--mujs-background-color, hsl(222, 14%, 33%)) !important;
359+
border: 1px solid var(--mujs-txt-color, hsl(0, 0%, 100%));
360+
border-radius: 16px;
361+
text-align: center;
362+
padding: .5em;
363+
z-index: 1;
364+
365+
.prompt-head {
366+
font-size: 18px;
367+
}
368+
369+
.prompt-body {
370+
display: grid;
371+
grid-auto-flow: column;
372+
grid-gap: .5em;
373+
padding-top: .5em;
374+
}
375+
376+
mujs-btn {
377+
&[data-command="prompt-deny"] {
378+
background: var(--mujs-sf-btn-color, hsl(12, 86%, 50%));
379+
border-color: var(--mujs-sf-btn-color, hsl(12, 86%, 50%));
380+
381+
&:hover {
382+
background: var(--mujs-sf-txt-color, hsl(12, 79%, 55%));
383+
border-color: var(--mujs-sf-txt-color, hsl(12, 79%, 55%));
384+
}
385+
}
386+
387+
&[data-command="prompt-confirm"] {
388+
background: var(--mujs-gf-color, hsl(204, 100%, 40%));
389+
border-color: var(--mujs-gf-color, hsl(204, 100%, 40%));
390+
391+
&:hover {
392+
background: var(--mujs-gf-btn-color, hsl(211, 87%, 56%));
393+
border-color: var(--mujs-gf-btn-color, hsl(211, 87%, 56%));
394+
}
395+
}
396+
}
397+
}
398+
}
339399
}
340400

341401
.mainframe {
@@ -356,6 +416,7 @@ mujs-main {
356416

357417
&.error {
358418
opacity: 1 !important;
419+
359420
count-frame {
360421
background: var(--mujs-even-err, hsl(0, 100%, 22%)) !important;
361422
}
@@ -401,7 +462,7 @@ mujs-header {
401462
height: -webkit-fit-content;
402463
gap: 1em;
403464

404-
> *:not(mujs-url) {
465+
>*:not(mujs-url) {
405466
height: fit-content;
406467
height: -moz-fit-content;
407468
height: -webkit-fit-content;
@@ -411,7 +472,7 @@ mujs-header {
411472
order: 0;
412473
flex-grow: 1;
413474

414-
> input {
475+
>input {
415476
width: 100%;
416477
height: 100%;
417478
background: var(--mujs-even-row, hsl(222, 14%, 18%));
@@ -506,6 +567,7 @@ mujs-body {
506567
.frame:not(.webext-page) {
507568
td {
508569
margin: 1rem !important;
570+
509571
&:not(.mujs-name, .install-btn) {
510572
width: auto !important;
511573
}
@@ -926,3 +988,19 @@ mu-jsbtn,
926988
mujs-btn {
927989
cursor: pointer !important;
928990
}
991+
992+
// .install-link {
993+
// transition: box-shadow .2s;
994+
// display: inline-block;
995+
// background-color: hsl(120, 100%, 16%);
996+
// padding: .5em 1em;
997+
// color: hsl(0, 0%, 100%);
998+
// text-decoration: none;
999+
// border-radius: .25rem 0 0 .25rem;
1000+
// }
1001+
1002+
// .install-help {
1003+
// background-color: hsl(120, 67%, 35%);
1004+
// color: hsl(0, 0%, 100%);
1005+
// border-radius: 0 .25rem .25rem 0;
1006+
// }

0 commit comments

Comments
 (0)