NYT Article Limit Remover

This script removes the limit on the number of articles you

  1. // ==UserScript==
  2. // @name NYT Article Limit Remover
  3. // @namespace http://userscripts.org/users/131241234
  4. // @include /^https?://[^/]*\.nytimes\.com/.*$/
  5. // @include http://*.nytimes.com/*
  6. // @version 3.1
  7. // @grant GM_addStyle
  8. // @grant GM_log
  9. // @grant GM_xmlhttpRequest
  10. // @run-at document-start
  11. // @description:en This script removes the limit on the number of articles you
  12. // can read at nytimes.com.
  13. // @description This script removes the limit on the number of articles you
  14. // ==/UserScript==
  15.  
  16.  
  17. log = GM_log;
  18. check_interval = 25, max_retry = 20, activeTime = 15000;
  19.  
  20. clearSettings();
  21.  
  22. waitFor('unsafeWindow.define', function(){
  23. unsafeWindow.define("auth/mtr", ["auth.mtr"], nil);
  24. unsafeWindow.define("auth/gateway", ['auth/gateway'], nil);
  25. unsafeWindow.define("auth/gateway/creatives", ['auth/gateway/creatives'], nil);
  26. });
  27.  
  28. GM_addStyle('.applicationButtonLt, #gatewayCreative {display: none!important;} #overlay {height:0px!important;} html, body {height: auto!important; overflow: visible!important;}');
  29.  
  30. if(window.location.search.indexOf("REFUSE_COOKIE_ERROR")>=0){
  31. try {
  32. window.location.href = "http://nytimes.com/" + window.location.search.match(/\/(.*)&/)[1];
  33. }
  34. catch(e){};
  35. }
  36.  
  37. var nl = window.location.search.replace(/_r=\d+/g, "_r=0");
  38. if(nl!=window.location.search)
  39. window.location.search = nl;
  40.  
  41. observer = new MutationObserver(function(mutations) {
  42. mutations.forEach(function(mutation) {
  43. for(var i = 0; i < mutation.addedNodes.length; i++)
  44. if(mutation.addedNodes[i].id=='overlay'){
  45. observer.disconnect();
  46. scrapePage();
  47. return;
  48. }
  49. });
  50. });
  51.  
  52. observer.observe(document, { childList: true, subtree: true } );
  53. setTimeout( function(){ observer.disconnect(); }, activeTime );
  54.  
  55. waitFor(
  56. function(){
  57. return (article = document.querySelector('#article, #content, #story')) && (articleText = article.innerHTML) || document.getElementById('articleBody');
  58. },
  59. null, activeTime
  60. );
  61.  
  62. function scrapePage(){
  63. if(document.getElementById('articleBody'))
  64. ;
  65. else
  66. if(('articleText' in window) && articleText.length > 0)
  67. write(articleText);
  68. else
  69. getPage();
  70. //alert('scrapePage');
  71. }
  72.  
  73. function write(text){
  74. /*var text = '';
  75. text_.split("\n").forEach(function(entry){
  76. text += entry.replace('script', 'noscript');
  77. });*/
  78. waitFor('article', function(){
  79. var div = document.createElement('div');
  80. var id = article.id;
  81. article.id = '';
  82. div.id = id;
  83. div.innerHTML = text;
  84. article.style.display = 'none';
  85. article.parentNode.insertBefore(div, article);
  86. article.parentNode.removeChild(article);
  87. }, null, activeTime);
  88. }
  89.  
  90. function getPage(){
  91. var retry = 0;
  92. (function getPage_(){
  93. if(retry++ < max_retry)
  94. GM_xmlhttpRequest({
  95. method: "GET",
  96. url: location.href,
  97. timeout: 20000 - 15000 / retry,
  98. onerror: arguments.callee,
  99. ontimeout: arguments.callee,
  100. onload: response
  101. });
  102. })();
  103. }
  104.  
  105. function response(resp){
  106. var div = document.createElement('div');
  107. div.innerHTML = resp.responseText;
  108. write(div.querySelector('#article, #content, #story').innerHTML);
  109. }
  110.  
  111. function waitFor(condition, callback, maxTime){
  112. var t = 0;
  113. if(typeof callback != 'function')
  114. var callback = function(){};
  115. (function(){
  116. if((typeof condition == 'function') && condition())
  117. return callback();
  118. if(typeof condition == 'string'){
  119. try {
  120. if(eval(condition))
  121. return callback();
  122. }
  123. catch(e){}
  124. }
  125. if((typeof maxTime != 'undefined') && (t>= maxTime))
  126. return;
  127. t += check_interval;
  128. window.setTimeout(arguments.callee, check_interval);
  129. })();
  130. }
  131.  
  132. function clearSettings(){
  133. document.cookie = "nyt-m=;path=/;domain=nytimes.com;expires=expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  134. unsafeWindow.localStorage.removeItem('nyt-m');
  135. unsafeWindow.name = '';
  136. }
  137.  
  138. function nil(){ return null; }