HI,
I think that should do the trick ;)
var links = document.querySelectorAll('a[rel="next"], a[rel="Next"], a[rel="NEXT"]');
for(var i=0; i
Regards
Reek
Actually, I wanted to remove the <link> tags that have "next" in the rel attribute, not the <a> tags. It's OK, though. I was able to modify the code anyway.
var links = document.querySelectorAll('link[rel*="next"], link[rel*="Next"], link[rel*="NEXT"]');
for(var i=0; i
Another question, how would I add exceptions to this piece of coding. Say I wanted to exclude certain websites containing a string of characters from a given list. How would I do that?
Since Greasemonkey doesn't prioritize the @exclude metatag, you'd have to use Scriptish or implement the check manually:
var excludedHosts = ['google.co', 'amazon.co', 'microsoft.com']; // "co" will also catch "com"
var host = document.location.hostname;
for (var h of excludedHosts)
if (host.contains(h))
return;
The above code is FF-only as it uses "...of..." ES6 iteration. Or you can check for an exact match which is faster:
var excludedHosts = ['www.google.com', 'www.amazon.com', 'www.microsoft.com'];
if (excludedHosts.indexOf(document.location.hostname) > -1)
return;
var excludedHosts = ['tinhte.vn', 'proboards.com', 'v2ex.com'];
if (excludedHosts.indexOf(document.location.hostname) > -1)
var links = document.querySelectorAll('link[rel="next"], link[rel="Next"], link[rel="NEXT"]');
for(var i=0; i
Apparently you want to skip processing certain LINK tags which point to an excluded host. I thought you needed to prevent the script from running on certain sites. Well, then, here's an untested example (Firefox-only):
var excludedHosts = ['tinhte.vn', 'proboards.com', 'v2ex.com'];
var links = document.querySelectorAll('link[rel*="next"], link[rel*="Next"], link[rel*="NEXT"]');
for(var link of links) {
var linkhost = '.' + new URL(link.href).hostname;
for (var xh of excludedHosts)
if (!linkhost.contains('.' + xh))
link.removeAttribute('rel');
}
Here's another idea. What about a script that removes the rel='next' attribute from <link> tags on a page only when another element on the page has "hentry" or "h-entry" in it's class name?
var anotherElement = document.querySelector('#some > div');
var shouldDelete = anotherElement && anotherElement.className.match(/(^|\s)h-?entry(\s|$)/);
if (shouldDelete) {
var links = document.querySelectorAll('link[rel*="next"], link[rel*="Next"], link[rel*="NEXT"]');
for(var link of links)
link.removeAttribute('rel');
}
Could I have that revised without the excluding links?
I've updated the code above.
It doesn't seem to be working.
Well, if you haven't changed the dummy DOM selector (#some > div
) in the code above to an actual one, of course it won't work.
Then what should be in place of the dummy selector?
There should be an actual selector that identifies "another element on the page" unambiguously.
If you don't know how to write css selectors then just give a link to that page or paste its entire html source to a new text file and upload it here as an attachment.
I think I have it now. Thanks for the help.
Change Link Attribute in tag
If possible, would someone please give me a script that changes/disables the link element with the attribute of rel="next" or "NEXT", or "Next" ? Not making it case sensitive would be nice. The
tag is within the , and I want it working for any page.