1+ // TODO: add translations to "Install as user style?"
2+
13// #region Console
24const dbg = ( ...msg ) => {
35 const dt = new Date ( ) ;
@@ -508,6 +510,7 @@ class Memorize {
508510 }
509511}
510512const memory = new Memorize ( ) ;
513+ //#region Icon SVGs
511514const 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 = / p r o m p t - / . 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 = / c o n f i r m / . 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 ( / \. u s e r \. c s s $ / , '.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' , {
0 commit comments