follow page

10.4.2021, 17:52:31

  1. // ==UserScript==
  2. // @name follow page
  3. // @namespace Violentmonkey Scripts
  4. // @match *://rule34.xxx/*
  5. // @grant GM_setValue
  6. // @grant GM_getValue
  7. // @version 1.8
  8. // @author usnkw
  9. // @description 10.4.2021, 17:52:31
  10. // @require https://code.jquery.com/jquery-3.5.1.min.js
  11. // ==/UserScript==
  12.  
  13. var followList = [];
  14. var newList = [];
  15. var a = null;
  16. var auto = false;
  17.  
  18. $("document").ready(async function() {
  19. if ( window.location == window.parent.location ) {
  20. var tags = /tags=(.*)/gm.exec(document.location.href) == null ? null : /tags=(.*)/gm.exec(document.location.href)[1];
  21. if(tags == null) return;
  22. if(GM_getValue('followList') == undefined){ GM_setValue('followList', []);}
  23. if(GM_getValue('newList') == undefined){ GM_setValue('newList', []);}
  24. a = document.createElement("a");
  25. followList = GM_getValue('followList');
  26. newList = GM_getValue('newList');
  27. tags = tags.replace('+', ' ');
  28. tags = tags.replace('%20', ' ');
  29. for(var i = 0; i < tags.length; i++){
  30. if(followList.some( e => e['tagName'].trim() == tags.trim())){
  31. a.style.color = "red";
  32. }
  33. console.log('je');console.log(newList);console.log(tags);
  34. if(newList.some( e => e['tagName'].trim() == tags.trim())){
  35. newList = newList.filter( el => el.tagName.trim() != tags.trim());
  36. followList = followList.filter( el => el.tagName.trim() != tags.trim());
  37. followTag(); // remove the last saved post and refollow to refresh the post that is compared to
  38. GM_setValue('newList', newList);
  39. console.log('newList', newList);
  40. }
  41. }
  42. a.innerHTML = " <3 ";
  43. a.style.cursor = "pointer";
  44. a.onclick = followTag;
  45. document.getElementsByClassName("awesomplete")[0].appendChild(a);
  46.  
  47. var re = document.createElement("a");
  48. re.innerHTML = " look for news ";
  49. re.style.cursor = "pointer";
  50. re.onclick = checkForNewPosts;
  51. document.getElementsByClassName("awesomplete")[0].appendChild(re);
  52.  
  53. re = document.createElement("a");
  54. re.innerHTML = "<br >exprot ";
  55. re.style.cursor = "pointer";
  56. re.onclick = exportFav;
  57. document.getElementsByClassName("awesomplete")[0].appendChild(re);
  58.  
  59. re = document.createElement("a");
  60. re.innerHTML = "<br> import ";
  61. re.style.cursor = "pointer";
  62. re.onclick = importFav;
  63. document.getElementsByClassName("awesomplete")[0].appendChild(re);
  64.  
  65. re = document.createElement("a");
  66. re.innerHTML = "next";
  67. re.style.cursor = "pointer";
  68. re.onclick = next;
  69. document.getElementsByClassName("awesomplete")[0].appendChild(re);
  70.  
  71. re = document.createElement("a");
  72. re.innerHTML = "<br> random Tag";
  73. re.style.cursor = "pointer";
  74. re.onclick = random;
  75. document.getElementsByClassName("awesomplete")[0].appendChild(re);
  76.  
  77. re = document.createElement("a");
  78. re.innerHTML = "<br> search for all Tags";
  79. re.style.cursor = "pointer";
  80. re.onclick = searchForAll;
  81. document.getElementsByClassName("awesomplete")[0].appendChild(re);
  82.  
  83. refreshSidebar();
  84.  
  85. if(auto){
  86. checkForNewPosts();
  87. setInterval(() => { checkForNewPosts(); refreshSidebar();}, 600000);
  88. }
  89. }
  90. });
  91. function exportFav(){
  92. download(JSON.stringify(followList), 'followList', '.txt')
  93. }
  94. function importFav(){
  95. var input = document.createElement('input');
  96. input.type = 'file';
  97.  
  98. input.onchange = e => {
  99. var file = e.target.files[0];
  100. var reader = new FileReader();
  101. reader.readAsText(file,'UTF-8');
  102. reader.onload = readerEvent => {
  103. var content = readerEvent.target.result;
  104. followList = JSON.parse(content);
  105. GM_setValue('followList', followList);
  106. refreshSidebar();
  107. }
  108. }
  109.  
  110. input.click();
  111. }
  112. function download(data, filename, type) {
  113. var file = new Blob([data], {type: type});
  114. if (window.navigator.msSaveOrOpenBlob) // IE10+
  115. window.navigator.msSaveOrOpenBlob(file, filename);
  116. else { // Others
  117. var a = document.createElement("a"),
  118. url = URL.createObjectURL(file);
  119. a.href = url;
  120. a.download = filename;
  121. document.body.appendChild(a);
  122. a.click();
  123. setTimeout(function() {
  124. document.body.removeChild(a);
  125. window.URL.revokeObjectURL(url);
  126. }, 0);
  127. }
  128. }
  129. async function refreshSidebar(){
  130. var sideElm = document.getElementsByClassName("sidebarRight")[0] == undefined? document.getElementsByClassName("content")[0] : document.getElementsByClassName("sidebarRight")[0];
  131. sideElm.innerHTML = "";
  132. followList.sort(function(a, b){
  133. var nameA=a.tagName.toLowerCase(), nameB=b.tagName.toLowerCase()
  134. if (nameA < nameB) return -1
  135. if (nameA > nameB) return 1
  136. return 0
  137. })
  138.  
  139. for(var i = 0; i < followList.length; i++){
  140. var tag = document.createElement("a");
  141. tag.innerHTML = followList[i].tagName + "<br>";
  142. tag.style.displayStyle = "inline";
  143. tag.style.padding = ".3em 1em .3em 1em";
  144. tag.style.lineHeight = "3";
  145. tag.style.cursor = "pointer";
  146. tag.style.backgroundColor = "#f55c51"
  147. tag.style.width = "100%";
  148. tag.style.borderRadius = "10px";
  149. tag.href = "https://rule34.xxx/index.php?page=post&s=list&tags=" + followList[i]["tagName"];
  150. if(newList.some( e => e['tagName'] == followList[i]["tagName"])){
  151. tag.style.backgroundColor = "#b6eb1a";
  152. tag.style.color = "#000000";
  153. }
  154. sideElm.appendChild(tag);
  155. }
  156. }
  157. async function checkForNewPosts(){
  158. for(var i = 0; i < followList.length; i++){
  159. a.innerHTML = "<3" + " checking: " + followList[i]["tagName"] + "<br>";
  160. var postId = await getFirstPostId("https://rule34.xxx/index.php?page=post&s=list&tags=" + followList[i]["tagName"]);
  161. console.log(followList[i]["tagName"] + " : ", postId, followList[i]["postId"]);
  162. if(postId != followList[i]["postId"] && !(newList.some(e => e['tagName'] == followList[i]['tagName']))){
  163. newList.push({"tagName": followList[i]["tagName"], "postId":postId});
  164. GM_setValue('newList', newList);
  165. console.log('newList', newList);
  166. }
  167. }
  168. a.innerHTML = "<3";
  169. refreshSidebar();
  170. }
  171. async function followTag(){
  172. var tagname = document.getElementsByName("tags")[0].value;
  173. var festPostId = document.getElementsByClassName("thumb")[0] == undefined ? 0 : document.getElementsByClassName("thumb")[0].id;
  174.  
  175. if(!followList.some( e => e['tagName'].trim() == tagname.trim())){
  176. followList.push({"tagName":tagname, "postId":festPostId});
  177. GM_setValue('followList', followList);
  178. }else{
  179. followList = followList.filter( el => el.tagName.trim() != tagname.trim());
  180. GM_setValue('followList', followList);
  181. }
  182. a.style.color = a.style.color == "red" ? "#ffffff" : "red";
  183. refreshSidebar();
  184. }
  185. async function getFirstPostId(url){
  186. return new Promise(function(resolve, reject) {
  187. var ifream = document.createElement("iframe");
  188. ifream.src = url;
  189. ifream.onload = function() {
  190. var elm = $("iframe").contents().find("span[class='thumb']")[0];
  191. resolve(elm == undefined ? 0 : elm.id);
  192. ifream.parentNode.removeChild(ifream);
  193. }
  194. document.body.appendChild(ifream);
  195. });
  196. }
  197. async function next(){
  198. console.log(newList[0]);
  199. location.href = 'https://rule34.xxx/index.php?page=post&s=list&tags=' + newList[0].tagName;
  200. }
  201. async function random(){
  202. location.href = 'https://rule34.xxx/index.php?page=post&s=list&tags=' + followList[Math.floor(Math.random() * followList.length)].tagName;
  203. }
  204. async function searchForAll(){
  205. var allTags = "( " + followList.reduce( (x,i) => x += i.tagName.replace(" ", " ~ ") + " ~ " , "") + " )";
  206. console.log(allTags);
  207. location.href = 'https://rule34.xxx/index.php?page=post&s=list&tags=' + allTags;
  208. }