User:MolecularPilot/ExternalLinkScreen.js
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function() {
// Function to check if a link is external, excluding Wikimedia and Wikipedia domains
function isExternalLink(link) {
const hostname = window.location.hostname;
const excludedDomains = ['wikimedia.org', 'wikipedia.org'];
// Check if the link is external and not from Wikimedia or Wikipedia
return link.hostname !== hostname && link.hostname !== '' &&
!excludedDomains.some(domain => link.hostname.endsWith(domain));
}
// Get all anchor elements
const anchors = document.querySelectorAll('a');
// Loop through all anchor elements
anchors.forEach(function(anchor) {
const href = anchor.getAttribute('href');
if (href && isExternalLink(anchor)) {
// Update the href to the link checker tool with the original URL as a query parameter
anchor.setAttribute('href', 'https://molecularbot2.toolforge.org/linkCheck.html?url=' + encodeURIComponent(href));
}
});
})();