Is there a way to use Greasemonkey or Tampermonkey to automatically open the definition on Dictionary.com at Thesaurus.com, and vice versa, when clicking specific links? (Shown in red)
My initial thought is to retrieve the word being searched from the URL using window.location.pathname
, and then place it in the hostname of the opposite link.
The Thesaurus.com link HTML:
<a href="http://www.thesaurus.com/" data-linkid="qxnxzj">Thesaurus.com</a>
The Dictionary.com link HTML:
<a href="http://www.dictionary.com/" data-linkid="tqks0v">Dictionary.com</a>
I considered using either
document.querySelectorAll("a[href='http://www.thesaurus.com']");
or document.querySelectorAll('[data-linkid=qxnxzj]');
to select the links.
However, I am unsure about relying on the data-linked attribute if it gets changed by the web developer.
As for the implementation, should I listen for all clicks on the document
, or just on <a>
tags? What would be the most efficient approach?
Additionally, is there a way to make these links open in a new tab when ctrl+clicked, or in a new window when shift+clicked? Currently, they both open in the same browser tab.