您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
A script to improve the use of rule34!
当前为
// ==UserScript== // @name Better Rule34 // @name:fr Meilleure règle 34 // @namespace http://tampermonkey.net/ // @version 0.1 // @description A script to improve the use of rule34! // @description:fr Un script pour améliorer l'utilisation de rule34! // @author You // @match https://rule34.xxx/* // @icon https://www.google.com/s2/favicons?sz=64&domain=rule34.xxx // @grant GM_addStyle // @license MIT // ==/UserScript== const settings = `{ "theme": "dark", "re-add deleated posts" : "false", "resizePosts" : "false" }`; const settingsObject = JSON.parse(settings); const dark = { "primary": "#121212", "secondary": "#000011", "contrast" : "gray" }; const themes = { "dark": dark } function setTheme(){ let currentTheme = themes[settingsObject.theme]; if(currentTheme){ const css = ` body { background-color: ${currentTheme.primary}; } .flat-list{ background-color: ${currentTheme.secondary}; } div#header ul#subnavbar { background-color: ${currentTheme.secondary}; } div#header ul#navbar li.current-page { background-image: url(https://imgs.search.brave.com/77L3MmxBu09NuN5WiX4HlbmWjjUe7eAsmBbakS7-DTo/rs:fit:120:120:1/g:ce/aHR0cHM6Ly91cGxv/YWQud2lraW1lZGlh/Lm9yZy93aWtpcGVk/aWEvY29tbW9ucy90/aHVtYi8wLzAyL1Ry/YW5zcGFyZW50X3Nx/dWFyZS5zdmcvMTIw/cHgtVHJhbnNwYXJl/bnRfc3F1YXJlLnN2/Zy5wbmc);; } .current-page { background-color: ${currentTheme.secondary}; background-color: brightness(110%); } .manual-page-chooser>input[type=text]{ background-color: ${currentTheme.secondary}; } .manual-page-chooser>input[type=submit]{ background-color: ${currentTheme.secondary}; color: ${currentTheme.contrast}; } div.tag-search input[type=text]{ background-color: ${currentTheme.secondary}; color: ${currentTheme.contrast}; } div.tag-search input[type=submit]{ background-color: ${currentTheme.secondary}; color: ${currentTheme.contrast}; } div.tag-search button{ background-color: ${currentTheme.secondary}; color: ${currentTheme.contrast}; } `; GM_addStyle(css); if(settingsObject.resizePosts == "true"){ if(document.getElementById("image")){ document.getElementById("image").class = "content" GM_addStyle(".content{max-height: 35%; overflow: auto;}"); }else{ GM_addStyle(".content{max-height: 45%; max-width: 45%; overflow: auto;}"); } } } } function getRandomElementFromRule34(tags, index) { return fetch(`https://rule34.xxx/index.php?page=dapi&s=post&q=index&tags=${tags}`) .then(response => response.text()) .then(xml => { const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xml, "application/xml"); const posts = xmlDoc.getElementsByTagName("post"); if(posts.length > 0) { if (index !== undefined) { const specificElement = posts[index]; if(specificElement.hasAttribute("id")) { const id = specificElement.getAttribute("id"); return id; } else { console.error("The specific element does not have an id attribute") } } else { const randomElement = posts[Math.floor(Math.random() * posts.length)]; if(randomElement.hasAttribute("id")) { const id = randomElement.getAttribute("id"); return id; } else { console.error("The random element does not have an id attribute") } } } else { console.error("No post elements found in the xml") } }); } function getTagsFromUrl(currentUrl) { if(currentUrl.startsWith("https://rule34.xxx/index.php?page=post&s=list&tags=")) { return currentUrl.replace("https://rule34.xxx/index.php?page=post&s=list&tags=", ""); } } function creatLinks(){ if(window.location.href.startsWith("https://rule34.xxx/index.php?page=post&s=list&tags=")) { var anchors = document.getElementsByClassName("image-list")[0].getElementsByTagName("a"); for (var i = 0; i < anchors.length; i++) { anchors[i].href = anchors[i].href + "&srchTags=" + getTagsFromUrl(window.location.href) + "&index=" + i.toString() } } } function nextPost(){ const urlParts = window.location.href.split("&"); const srchTags = urlParts.find(part => part.startsWith("srchTags=")); const index = urlParts.find(part => part.startsWith("index=")); console.log(srchTags, index) getRandomElementFromRule34(srchTags.replace("srchTags=", ""),Number(index.replace("index=", "")) + 2).then(id => { window.location.href = "https://rule34.xxx/index.php?page=post&s=view&id=" + id + "&" + srchTags + "&index=" + (Number(index.replace("index=", "")) + 1).toString(); }); } function backPost(){ const urlParts = window.location.href.split("&"); const srchTags = urlParts.find(part => part.startsWith("srchTags=")); const index = urlParts.find(part => part.startsWith("index=")); console.log(srchTags, index) getRandomElementFromRule34(srchTags.replace("srchTags=", ""),Number(index.replace("index=", "")) - 1).then(id => { window.location.href = "https://rule34.xxx/index.php?page=post&s=view&id=" + id + "&" + srchTags + "&index=" + (Number(index.replace("index=", "")) - 1).toString(); }); } function makeButtons(){ function randomVideo(){ let tags = document.querySelector("input[name='tags']").value.replace(/ /g, "+"); const currentUrl = window.location.href; const tagsFromUrl = getTagsFromUrl(currentUrl); if(tagsFromUrl) { tags = tagsFromUrl; } getRandomElementFromRule34(tags).then(id => { window.location.href = `https://rule34.xxx/index.php?page=post&s=view&id=${id}`; }); } let btn = document.createElement("button"); btn.innerHTML = "Random"; btn.onclick = randomVideo; if(document.getElementsByClassName("tag-search")[0]){document.getElementsByClassName("tag-search")[0].appendChild(btn)}; if(document.getElementsByClassName("image-sublinks")[0]){ let btn3 = document.createElement("button"); btn3.innerHTML = "back"; btn3.onclick = backPost; document.getElementsByClassName("image-sublinks")[0].appendChild(btn3); let btn2 = document.createElement("button"); btn2.innerHTML = "next"; btn2.onclick = nextPost; document.getElementsByClassName("image-sublinks")[0].appendChild(btn2); } } const imageSublinks = document.getElementsByClassName("image-sublinks")[0]; if (imageSublinks) { document.addEventListener("keydown", function(event) { if (event.keyCode === 39) { nextPost(); } else if (event.keyCode === 37) { backPost(); } }); } makeButtons(); creatLinks() setTheme()