custom profile page rule34.xxx

10.4.2021, 17:52:31

  1. // ==UserScript==
  2. // @name custom profile page rule34.xxx
  3. // @namespace Violentmonkey Scripts
  4. // @match https://rule34.xxx/index.php
  5. // @grant GM_setValue
  6. // @grant GM_getValue
  7. // @version 1.1
  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.  
  14. var threadUrl = "https://rule34.xxx/index.php?page=forum&s=view&id=12998&pid=";
  15. var dir = GM_getValue('dir');
  16.  
  17. $("document").ready(async function() {
  18. var li = document.createElement("li");
  19. li.style.cursor = "pointer";
  20. var a = document.createElement("a");
  21. a.innerHTML = "Refresh Database";
  22. a.onclick = updateDb;
  23. li.appendChild(a);
  24. document.getElementsByClassName("flat-list")[0].appendChild(li);
  25. if(window.location.href.includes("profil")){
  26. addView(document.getElementsByTagName("h2")[1].innerText);
  27. }
  28. });
  29. function addView(userName){
  30. var div = document.createElement("div");
  31. for(var i = 0; i < dir.length; i++){
  32. if(dir[i][0] == userName){
  33. var text = encodeHTML(dir[i][1]);
  34. console.log(dir[i][1]);
  35. var matches = text.match(/(?<=\[).+?(?=\])/g);
  36. if(matches != null){
  37. for(var i = 0; i < matches.length; i++){
  38. var type = matches[i].match(/([a-z]*):(.*)/)[1];
  39. switch(type){
  40. case "img":
  41. var elm = "<img src=\"" + encodeHTML(matches[i].match(/([a-z]*):(.*)/)[2]) +"\" style='height:150px'>"
  42. text = text.replace("["+matches[i]+"]", elm);
  43. break;
  44. case "link":
  45. var t = encodeHTML(matches[i].match(/([a-z]*):(.*)/)[2]);
  46. var elm = "<a href=\"" + t +"\">"+t+"</a>"
  47. text = text.replace("["+matches[i]+"]", elm);
  48. break;
  49. case "br":
  50. var elm = "<br>"
  51. text = text.replace("["+matches[i]+"]", elm);
  52. break;
  53. }
  54. }
  55. }
  56. div.innerHTML = text;
  57. document.getElementById("content").prepend(div);
  58. break;
  59. }
  60. }
  61. }
  62. async function updateDb(){
  63. console.log("Fetching!");
  64. var postCount = await getPostCount();
  65. for(var i = 0; i <= postCount; i+=15){
  66. dir = (await fetchPosts(threadUrl + i));
  67. }
  68. console.log(dir);
  69. GM_setValue('dir', dir);
  70. }
  71. async function fetchPosts(url){
  72. return new Promise(function(resolve, reject) {
  73. var ifream = document.createElement("iframe");
  74. ifream.src = url;
  75. ifream.onload = function() {
  76. var author = $("iframe").contents().find(".author a[href]");
  77. var links = $("iframe").contents().find(".body").find("a[rel='nofollow']");
  78. for(var i = 0; i < links.length; i++){
  79. links[i].outerText = links[i].href;
  80. }
  81. var post = $("iframe").contents().find(".body");
  82. var out = [];
  83. for(var i = 0; i < author.length; i++){
  84. out.push([author[i].innerHTML, post[i].innerText]);
  85. ifream.parentNode.removeChild(ifream);
  86. }
  87. resolve(out);
  88. }
  89. document.body.appendChild(ifream);
  90. });
  91. }
  92. async function getPostCount(){
  93. return new Promise(function(resolve, reject) {
  94. var ifream = document.createElement("iframe");
  95. ifream.src = threadUrl;
  96. ifream.onload = function() {
  97. var elm = $("iframe").contents().find("a[alt='last page']")[0];
  98. if(elm != null){
  99. resolve(parseInt(/pid=([0-9]*)/gm.exec($("iframe").contents().find("a[alt='last page']")[0].href)[1]));
  100. }
  101. resolve(0);
  102. ifream.parentNode.removeChild(ifream);
  103. }
  104. document.body.appendChild(ifream);
  105. });
  106. }
  107. function encodeHTML(s) {
  108. return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
  109. }