raingart / Nova-YouTube-extension

Apache License 2.0
199 stars 9 forks source link

How to import settings while using Tampermonkey? #17

Closed lakshits11 closed 1 year ago

lakshits11 commented 1 year ago

Describe the bug

I am clicking on import settings but nothing happens, while when I click on export settings, it quickly exports them. But having problems importing the settings.

image

raingart commented 1 year ago

These are Brave problems. Everything works correctly in other browsers. Let them know if you want.

Tampermonkey does not allow you to directly edit script data, unlike Violentmonkey, for example: Screenshot_2

Also, Brave is good at pretending to be Chrome, which prevents it from being detected and using a different import method for it. Screenshot_1

I can suggest that you replace this piece of code yourself:

current/old
   GM_registerMenuCommand('Import settings', () => {
      let f = document.createElement('input');
      f.type = 'file';
      f.accept = 'application/JSON';
      f.style.display = 'none';
      f.addEventListener('change', function () {
            let files =   Array.from(f.files);
            console.log(files);
               return          
         if (f.files.length !== 1) return alert('file empty');
         let rdr = new FileReader();
         rdr.addEventListener('load', function () {
            try {
               GM_setValue(configStoreName, JSON.parse(rdr.result));
               alert('Settings imported');
               location.reload();
            }
            catch (err) {
               alert(`Error parsing settings\n${err.name}: ${err.message}`);
            }
         });
         rdr.addEventListener('error', error => alert('Error loading file\n' + rdr.error));
         rdr.readAsText(f.files[0]);
      });
      document.body.append(f);
      f.click();
      f.remove();
   });
new
GM_registerMenuCommand('Import settings', () => {
       if(json = JSON.parse(prompt('Enter json file context'))) {
           GM_setValue(configStoreName, json);
           alert('Settings imported');
           location.reload();
       } else alert('Import failed');
   });
lakshits11 commented 1 year ago

Well I used violentmonkey and was able to import the settings.