Advertisement
13Blue13

FFB Script

Jul 19th, 2021 (edited)
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         FFBSCRIPT
  3. // @namespace    http://tampermonkey.net/
  4. // @version      25/01/2023
  5. // @description  Trying to make something a little useful
  6. // @author       Blue
  7. // @match        https://footfetishbooru.booru.org/*
  8. // @exclude      https://footfetishbooru.booru.org/index.php?page=login*
  9. // @exclude      https://footfetishbooru.booru.org/index.php?page=post&s=add*
  10. // @exclude      https://footfetishbooru.booru.org/index.php?page=favorites&s=view&id=*
  11. // @grant        GM_addStyle
  12. // ==/UserScript==
  13.  
  14. unsafeWindow.getUrlVars = getUrlVars;
  15. unsafeWindow.bluesConfig = {
  16.     scoreCount: true, //Show a score count above posts while searching.
  17.     tagCount: true, //Show tag count above posts while searching.
  18.     uploaderName: true, //Show uploader name above posts while searching.
  19.     imageSizeFIX: true, //Attempt to prevent huge posts. may break NOTES!
  20.     sauceNAO: true, //Adds the sauceNAO link on posts when it can.
  21.     sauceURL: true, //Turns the sauce per post into a URL, imporoper urls will be broken links.
  22. };
  23.  
  24. function getUrlVars(url) { //Nicked
  25.     var hash;
  26.     var myJson = {};
  27.     var hashes = url.slice(url.indexOf('?') + 1).split('&');
  28.     for (var i = 0; i < hashes.length; i++) {
  29.         hash = hashes[i].split('=');
  30.         myJson[hash[0]] = hash[1];
  31.         // If you want to get in native datatypes
  32.         // myJson[hash[0]] = JSON.parse(hash[1]);
  33.     }
  34.     return myJson;
  35. }
  36.  
  37. (function() {
  38.     'use strict';
  39.     const config = unsafeWindow.bluesConfig;
  40.     console.log("Script By Blue"); //Also shows it has loaded
  41.     //OTHER
  42.     if (config.sauceURL) {
  43.         try {
  44.             if (document.body.innerHTML.includes("\n          Source: ")) { //Making sure I don't break other pages
  45.                 var sauce = document.body.innerHTML.split("\n          Source: ").pop().split(" <br")[0];
  46.                 console.log("Sauce: " + sauce); //This is to find a sauce to a post.
  47.                 if (sauce) {
  48.                     document.getElementsByTagName("ul")[1].innerHTML = document.getElementsByTagName("ul")[1].innerHTML.replace(sauce, "<a href=\"" + sauce + "\">" + sauce + "</a>"); //Replace the sauce with an actual href to the sauce.
  49.                 }
  50.             }
  51.         } catch {}
  52.     }
  53.     if (config.sauceNAO) {
  54.         if (document.body.innerHTML.includes('<img alt="img" src="')) {
  55.             var source = document.body.innerHTML.split('<img alt="img" src="').pop().split("\"")[0];
  56.             console.log("Source: " + source); //This is to find a source to a post image.
  57.         }
  58.         for (let i = 0; i < document.getElementsByTagName("li").length; i++) {
  59.             if (document.getElementsByTagName("li")[i].innerHTML == "<br><br><br><br><br><br><br><br>") {
  60.                 document.getElementsByTagName("li")[i].innerHTML = '<li><br><a href=\"https://saucenao.com/search.php?url=' + source + '">[SauceNAO]</a><br><br><br><br><br><br></li>';
  61.             }
  62.         };
  63.     }
  64.     //Resize Images etc
  65.     if (config.imageSizeFIX) {
  66.         if (document.getElementById("image")) {
  67.             document.getElementById("image").style.width = "auto";
  68.             document.getElementById("image").style["max-width"] = "80%";
  69.         }
  70.         if (document.getElementById("note-container")) {
  71.             document.getElementById("note-container").style.width = "auto";
  72.         }
  73.         if (document.getElementsByClassName("sidebar")[0]) { //Tags List
  74.             document.getElementsByClassName("sidebar")[0].style.width = "auto";
  75.             document.getElementsByClassName("sidebar")[0].style["max-width"] = "20%";
  76.         }
  77.     }
  78.     //Get artist
  79.     var tags = " " + document.getElementById("tags").innerText + " "
  80.     var artist = document.getElementById("tags").innerText.split(" ")[document.getElementById("tags").innerText.split("_(artist) ")[0].split(" ").length - 1].split("_(artist)")[0];
  81.     if(tags.indexOf("_(artist) ") > -1) {
  82.         var artistTagNo = document.getElementById("tags").innerText.split("_(artist) ")[0].split(" ").length - 1;
  83.         var artistTag = document.getElementById("tag_list").childNodes[3].children[artistTagNo];
  84.         var artistNo = artistTag.innerHTML.split("</a> ")[1].split("</span>")[0];
  85.         console.log(artist, artistTagNo, artistTag);
  86.         artistTag.hidden = true;
  87.         document.getElementById("tag_list").innerHTML = `<h6>Artist</h6><ul><li><span>? <a style="color: #9093ff;" href="index.php?page=post&amp;s=list&amp;tags=${artist}_(artist)">${artist}</a> ${artistNo}</span></li></ul>` + document.getElementById("tag_list").innerHTML;
  88.     }
  89.     if (
  90.         config.scoreCount ||
  91.         config.tagCount ||
  92.         config.uploaderName
  93.     ) {
  94.         //Adding styles
  95.         GM_addStyle('.ratingnumber   {font-size:12px;background-color:#2A2A2A;line-height: 16px;text-align: center;color:#2DBAE5;z-index: 2;border-radius: 3px;position: absolute;left: 15px;   top: 15px;}');
  96.         GM_addStyle('.tagcountnumber {font-size:12px;background-color:#2A2A2A;line-height: 16px;text-align: center;color:#2DBAE5;z-index: 2;border-radius: 3px;position: absolute;left: 15px;bottom: 30px;}');
  97.         GM_addStyle('.uploadername   {font-size:12px;background-color:#2A2A2A;line-height: 16px;text-align: center;color:#2DBAE5;z-index: 2;border-radius: 3px;position: absolute;left: 15px;bottom: 15px;}');
  98.         GM_addStyle('.remove         {font-size:12px;background-color:#A22A2A;line-height: 16px;text-align: center;              z-index: 2;border-radius: 3px;position: absolute;left: 15px;bottom: 00px;}');
  99.         GM_addStyle('.thumb {display: inline-block;background-color:#333;border-radius: 30px;position: relative;text-align: center;padding-top: 20px; padding-bottom: 0px;margin-bottom: 5px;margin-right: 10px;}');
  100.         document.getElementsByClassName("thumb").forEach(p => {
  101.             var uploaderName = ""
  102.             var postID = p.firstChild.id.substr(1)
  103.             try {
  104.                 uploaderName = p.children[1].firstChild.data.split(`, 'user':'`).pop().split(`'}\n`)[0] || "";
  105.             } catch {
  106.                 uploaderName = p.firstChild.firstChild.title.split(' user:').pop().split(' ')[0];
  107.             }
  108.             if (config.scoreCount) {
  109.                 p.innerHTML += `<span class="ratingnumber">${p.firstChild.firstChild.title.split('score:').pop().split(' ')[0]}</span>`;
  110.             }
  111.             if (config.tagCount) {
  112.                 var tagCount = (p.firstChild.firstChild.title.split(' score:')[0].split(' ').length - 2);
  113.                 p.innerHTML += `<span class="tagcountnumber">T:${tagCount}</span>`;
  114.                 if(tagCount < 5){p.style="background-color:#dd0";}
  115.             }
  116.             if (uploaderName && config.uploaderName) {
  117.                 p.innerHTML += `<span class="uploadername"><a href="https://footfetishbooru.booru.org/index.php?page=account_profile&uname=${uploaderName}">U/${uploaderName}</a></span>`;
  118.             }
  119.         });
  120.         //Sorts a glitch on profiles
  121.         document.getElementsByClassName("ratingnumber").forEach(x => {
  122.             if (x.children.length > 0) {
  123.                 x.firstChild.remove()
  124.             }
  125.         });
  126.         document.title = "FFB";
  127.  
  128.         switch (getUrlVars(document.URL)?.s) { //Stuff
  129.             case "list": //Exploring posts
  130.                 document.onkeydown = checkKey;
  131.                 break;
  132.             default:
  133.  
  134.         }
  135.  
  136.         function checkKey(e) {
  137.             if(document.activeElement.nodeName != "INPUT"){ //Checks if key is pressed OUTSIDE of an input to avoid triggering while you type or edit tags etc
  138.                 var pid = window.location.href.split("&pid=")[1] || 0;
  139.                 e = e || window.event;
  140.                 var newPid = 0;
  141.                 switch (e.keyCode) {
  142.                     case 37: //Left Arrow
  143.                         newPid = pid - 20
  144.                         if (newPid > -1) {
  145.                             window.location.href=(window.location.href.split("&pid=")[0] + "&pid=" + newPid)
  146.                         }
  147.                         break;
  148.                     case 39: //Right Arrow
  149.                         newPid = pid - -20
  150.                         window.location.href=(window.location.href.split("&pid=")[0] + "&pid=" + newPid)
  151.                         break;
  152.                     default:
  153.                         //console.log(e.keyCode)
  154.                 }
  155.             }
  156.  
  157.         }
  158.     }
  159. })();
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement