@@ -64,7 +64,7 @@ const files = [
6464
6565const _browser = {
6666 delay : 200 ,
67- platform : "ios" ,
67+ platform : "macos" , // ios || macos
6868 runtime : {
6969 getURL ( ) {
7070 return "https://www.example.com/" ;
@@ -360,6 +360,20 @@ const _browser = {
360360 ]
361361 } ;
362362 }
363+ } else if ( name === "POPUP_INSTALL_CHECK" ) {
364+ response = random ( [
365+ { success : "Click to install" , installed : false } ,
366+ { success : "Click to re-install" , installed : true }
367+ ] ) ;
368+ response . metadata = {
369+ description : "This userscript re-implements the \"View Image\" and \"Search by image\" buttons into google images." ,
370+ grant : [ "GM.getValue" , "GM.setValue" , "GM.xmlHttpRequest" ] ,
371+ match : [ "https://www.example.com/*" , "https://www.example.com/somethingReallylong/goesRightHere" ] ,
372+ name : "Test Install Userscript" ,
373+ require : [ "https://code.jquery.com/jquery-3.5.1.min.js" , "https://code.jquery.com/jquery-1.7.1.min.js" ] ,
374+ source : "https://greasyforx.org/scripts/00000-something-something-long-name/code/Something%20something%20long20name.user.js"
375+ } ;
376+ // response.error = "something went wrong (dev)";
363377 }
364378 if ( ! responseCallback ) {
365379 return new Promise ( resolve => {
@@ -376,7 +390,13 @@ const _browser = {
376390 } ,
377391 tabs : {
378392 getCurrent ( /* responseCallback */ ) {
379- const response = { url : "https://www.filmgarb.com/foo.user.js" , id : 101 } ;
393+ const response = random ( [
394+ { url : "https://www.filmgarb.com/foo.user.js" , id : 101 } ,
395+ { url : `${ window . location . origin } /src/shared/dev/DEMO.Alert-URL.user.js` , id : 102 } ,
396+ { url : `${ window . location . origin } /src/shared/dev/DEMO.Alert-URL.user.js` , id : 103 } , // increase probability
397+ { url : window . location . href , id : 10 }
398+ ] ) ;
399+ console . info ( "browser.tabs.getCurrent" , response ) ;
380400 return new Promise ( resolve => {
381401 setTimeout ( ( ) => resolve ( response ) , _browser . delay ) ;
382402 } ) ;
@@ -392,18 +412,8 @@ const _browser = {
392412 } ,
393413 sendMessage ( tabId , message , responseCallback ) {
394414 let response = { } ;
395- if ( message . name === "POPUP_INSTALL_CHECK" ) {
396- response = {
397- success : "Click to install (test)" ,
398- metadata : {
399- description : "This userscript re-implements the \"View Image\" and \"Search by image\" buttons into google images." ,
400- grant : [ "GM.getValue" , "GM.setValue" , "GM.xmlHttpRequest" ] ,
401- match : [ "https://www.example.com/*" , "https://www.example.com/somethingReallylong/goesRightHere" ] ,
402- name : "Test Install Userscript" ,
403- require : [ "https://code.jquery.com/jquery-3.5.1.min.js" , "https://code.jquery.com/jquery-1.7.1.min.js" ] ,
404- source : "https://greasyforx.org/scripts/00000-something-something-long-name/code/Something%20something%20long20name.user.js"
405- }
406- } ;
415+ if ( message . name === "DEMO_MSG" ) {
416+ response = { } ;
407417 // response.error = "something went wrong (dev)";
408418 }
409419 if ( ! responseCallback ) {
@@ -481,6 +491,10 @@ function saveFile(content, lastMod, newFilename, oldName) {
481491 }
482492}
483493
494+ function random ( array ) {
495+ return array [ Math . floor ( Math . random ( ) * array . length ) ] ;
496+ }
497+
484498export const browser = _browser ;
485499
486500export default {
0 commit comments