Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Private messaging system #1606

Open
Spamme1 opened this Issue · 1 comment

2 participants

@Spamme1

I have the same script running in two different domains, it's a page with an iframe to another domain. To communicate between the two instances of the script (between the two domains) I use the window post message method, but this method isn't really stealth. If somebody want to detect the script it would be enough to add an event listener to the message event of the window.
It would be nice to have a private messaging system in GM, where you can send private messages to other scripts and they would be undetectable from the document.

@cletusc

You can already solve this using GM_setValue/GM_setValue, at least for communication among instances of the same script. Here is a very crude way of doing it, note that this is untested but it should get the idea across:

function addMessage(options) {
    var messages = JSON.parse(GM_getValue('messages', '[]'));
    messages.push(options);
    GM_setValue('messages', JSON.stringify(messages));
}
function getMessages() {
    var messages = JSON.parse(GM_getValue('messages', '[]'));
    return messages;
}

// Pass message
addMessage({
    // Your message details here
    domain: location.href,
    text: 'hello world'
});

// Get messages
var messages = getMessages();
for (var i = 0; i < messages.length; i++) {
    var message = messages[i];
    // Test for stuff here
    if (message.domain.indexOf('example.com')) {
        // Do stuff here
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.