Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited body
Source Link
Brock Adams
  • 94k
  • 23
  • 242
  • 312

Allow the userscript on both urls and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require@grant  GM_getValue //@require@grant  GM_setValue if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); window.open("http://example2.com","_self"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 

Allow the userscript on both urls and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require GM_getValue //@require GM_setValue if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); window.open("http://example2.com","_self"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 

Allow the userscript on both urls and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@grant  GM_getValue //@grant  GM_setValue if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); window.open("http://example2.com","_self"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 
Rollback to Revision 1
Source Link
woxxom
  • 75.2k
  • 15
  • 161
  • 164

Allow the userscript on both urls, open the new url in a new tab and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require GM_getValue //@require GM_setValue //@require GM_openInTab  if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); GM_openInTabwindow.open("http://example2.com","_self"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 

Allow the userscript on both urls, open the new url in a new tab and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require GM_getValue //@require GM_setValue //@require GM_openInTab  if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); GM_openInTab("http://example2.com"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 

Allow the userscript on both urls and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require GM_getValue //@require GM_setValue if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); window.open("http://example2.com","_self"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 
added 53 characters in body
Source Link
woxxom
  • 75.2k
  • 15
  • 161
  • 164

Allow the userscript on both urls, open the new url in a new tab and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require GM_getValue //@require GM_setValue //@require GM_openInTab  if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); window.openGM_openInTab("http://example2.com","_self"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 

Allow the userscript on both urls and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require GM_getValue //@require GM_setValue if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); window.open("http://example2.com","_self"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 

Allow the userscript on both urls, open the new url in a new tab and use GM_setValue/GM_getValue to organize the communication.

//@match http://example1.com //@match http://example2.com //@require GM_getValue //@require GM_setValue //@require GM_openInTab  if (location.href.indexOf('http://example1.com') == 0) { GM_setValue('id', Date.now() + '\n' + document.getElementById("myId").textContent); GM_openInTab("http://example2.com"); } else if (location.href.indexOf('http://example2.com') == 0) { var ID = GM_getValue('id', ''); if (ID && Date.now() - ID.split('\n')[0] < 10*1000) { ID = ID.split('\n')[1]; .............. use the ID } } 
  • This is a simplified example. In the real code you may want to use location.host or location.origin or match location.href with regexp depending on what the real urls are.

  • To pass complex objects serialize them:

     GM_setValue('test', JSON.stringify({a:1, b:2, c:"test"})); 

     try { var obj = JSON.parse(GM_getValue('test')); } catch(e) { console.error(e) } 
Source Link
woxxom
  • 75.2k
  • 15
  • 161
  • 164
Loading