erosman / support

Support Location for all my extensions
Mozilla Public License 2.0
175 stars 12 forks source link

[FireMonkey] GM_getValue/GM_setValue should be synchronous #98

Closed qsniyg closed 3 years ago

qsniyg commented 5 years ago

GM_getValue/GM_setValue are synchronous:

GM_setValue("variable", "test");
console.log(GM_getValue("variable"));
// logs 'test'

Looking at the source code (scriptAPI.js), it appears GM_setValue is just mapped directly to GM.setValue:

  script.defineGlobals({

    GM,
    GM_setValue:        GM.setValue,
    GM_getValue:        GM.getValue,
    GM_deleteValue:     GM.deleteValue,
    GM_listValues:      GM.listValues,
    GM_openInTab:       GM.openInTab,
    GM_setClipboard:    GM.setClipboard,
    GM_notification:    GM.notification,
    GM_xmlhttpRequest:  GM.xmlHttpRequest,
    GM_getResourceURL:  GM.getResourceUrl,
    GM_info:            GM.info,

    GM_fetch:           GM.fetch
  });

I'm not sure if GM_setValue needs to be changed, but GM_getValue returning a promise prevents some userscripts (including mine) from properly working. I'm guessing GM_listValues should also be synchronous.

Thank you for doing this by the way, it's great to have more options :)

erosman commented 3 years ago

I can't see it mentioned in the documentation, but it does support both.

I couldn't see it in their documentation and it is not open source any more.

This repository contains the source of the Tampermonkey extension up to version 2.9. All newer versions are distributed under a proprietary license.

https://github.com/Tampermonkey/tampermonkey

Our extension uses Google Analytics, a web analysis service from Google Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043 USA, hereinafter referred to as “Google“. Google Analytics employs so-called “cookies“, text files that are stored to your computer in order to facilitate an analysis of your use of the site.

For technical reasons (i.e. when the BlackCheck service checks for updates), data such as the following, which your internet browser transmits to us or to our web space provider (so called server log files), is collected: type and version of the browser you use operating system websites that you visit date and time of your visit your Internet Protocol (IP) address.

Tampermonkey Privacy Policy

erosman commented 3 years ago

GM_getValue & GM_listValues (v2.0)

Partial compatibility has been implemented. Please note:

The async GM.getValue & GM.listValues will get the values at that moment.

erosman commented 3 years ago

v2.0 released

erosman commented 2 years ago

v2.43 uploaded

Added experimental sync storage compatibility

chocolateboy commented 2 years ago

Just checked this and it doesn't appear to be working for GM_deleteValue:

Environment

Test

// ==UserScript==
// @name          FireMonkey Sync Storage Test
// @version       0.0.1
// @namespace     firemonkey-test
// @include       *
// @grant         GM_deleteValue
// @grant         GM_getValue
// @grant         GM_listValues
// @grant         GM_setValue
// ==/UserScript==

const KEY = 'test'
const VALUE = 42

const stored = Object.fromEntries(GM_listValues().map(key => [key, GM_getValue(key)]))

console.log('stored:', stored)

if (GM_getValue(KEY)) {
    GM_deleteValue(KEY)
    console.log(`deleted ${KEY}:`, GM_getValue(KEY) === undefined)
} else {
    GM_setValue(KEY, VALUE)
    console.log(`set ${KEY}:`, GM_getValue(KEY) === VALUE)
}

console.log('test:', GM_getValue(KEY))

Expected Output

stored: { }
set test: true
test: 42
stored: { test: 42 }
deleted test: true
test: undefined

Actual Output

stored:  { }
set test: true
test: 42
stored: { test: 42 }
deleted test: false
test: 42
erosman commented 2 years ago

I will check it. It might be related to (and fixed via) the issue #491

erosman commented 2 years ago

I checked and it is related to issue listed above and should be fixed in v2.57