Discussions » Creation Requests

Change Link Attribute in <head> tag

§
Posted: 2014-07-30

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.

§
Posted: 2014-08-03

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

§
Posted: 2014-08-03
Edited: 2014-08-03

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

§
Posted: 2015-01-25

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?

wOxxOmMod
§
Posted: 2015-01-26

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;
§
Posted: 2015-02-04

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

wOxxOmMod
§
Posted: 2015-02-04

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');
}
§
Posted: 2015-02-06

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?

wOxxOmMod
§
Posted: 2015-02-06
Edited: 2015-02-07
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');
}
§
Posted: 2015-02-07
Edited: 2015-02-07

Could I have that revised without the excluding links?

wOxxOmMod
§
Posted: 2015-02-07

I've updated the code above.

§
Posted: 2015-02-07

It doesn't seem to be working.

wOxxOmMod
§
Posted: 2015-02-07

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.

§
Posted: 2015-02-09

Then what should be in place of the dummy selector?

wOxxOmMod
§
Posted: 2015-02-09

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.

§
Posted: 2015-02-10

I think I have it now. Thanks for the help.

Post reply

Sign in to post a reply.