DZone article source redirector

Redirects reposted DZone articles to their source

  1. // ==UserScript==
  2. // @name DZone article source redirector
  3. // @namespace dzone
  4. // @description Redirects reposted DZone articles to their source
  5. // @include http://*.dzone.com/articles/*
  6. // @include https://*.dzone.com/articles/*
  7. // @include http://dzone.com/articles/*
  8. // @include https://dzone.com/articles/*
  9. // @version 3
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. function getLink() {
  14. var link = document.querySelector('div.attribution a');
  15. if (link) {
  16. return link;
  17. }
  18. }
  19.  
  20. var tries = 1;
  21. function checkLink(link) {
  22. console.debug('Checking link, try', tries++);
  23. if (link.href) {
  24. console.debug('Redirecting to ', link.href);
  25. window.location = link.href;
  26. } else if (tries < 10) {
  27. window.setTimeout(function() {
  28. checkLink(getLink());
  29. }, 2000);
  30. } else {
  31. console.debug('Article source not found.');
  32. };
  33. }
  34.  
  35. console.debug('Looking for article source...');
  36.  
  37. var link = getLink();
  38.  
  39. if (link != undefined) {
  40. checkLink(link);
  41. }