Last active
July 26, 2020 19:23
-
-
Save ewasion/9d20a6084fbe1a8bf2e0478beaf30bcd to your computer and use it in GitHub Desktop.
Eva's torrent highlighter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Eva's torrent highlighter | |
// @namespace https://github.com/ewasion | |
// @version 0.1.13 | |
// @description Highlight torrent info. | |
// @author Eva | |
// @homepage https://gist.github.com/ewasion/9d20a6084fbe1a8bf2e0478beaf30bcd | |
// @icon https://animebytes.tv/favicon.ico | |
// @updateURL https://gist.github.com/ewasion/9d20a6084fbe1a8bf2e0478beaf30bcd/raw/eva-torrent-highlighter.user.js | |
// @downloadURL https://gist.github.com/ewasion/9d20a6084fbe1a8bf2e0478beaf30bcd/raw/eva-torrent-highlighter.user.js | |
// @grant none | |
// @match https://animebytes.tv/* | |
// @license GPL-3.0 | |
// @run-at document-end | |
// ==/UserScript== | |
if(document.getElementById("content") != null && localStorage.getItem("userscript-highlight-installinfo") == null) { | |
const content = document.getElementById("content"); | |
userscriptInfo = document.createElement("div"); | |
userscriptInfo.id = "userscript-highlight-installinfo"; | |
userscriptInfo.innerHTML = `<style>#userscript-highlight-installinfo > h3 { color: #cacaca !important; } #userscript-highlight-installinfo > a { text-decoration: underline !important; color: #dad8d8 !important; } #userscript-highlight-installinfo > a:hover { color: #bababa !important; } #userscript-highlight-installinfo > span { position: absolute !important; top: 10px !important; right: 10px !important; border: 1px solid #cacaca !important; padding: 2px !important; }</style> | |
<h3>Eva's torrent highlighter</h3> | |
Thanks for installing my script!<br> | |
Before you write a post saying the script is broken, please read this.<br><br> | |
This userscript does not highlight anything by default, it just adds attributes which you can style.<br> | |
You will need an extension for userstyles.<br><br> | |
<a href="https://animebytes.tv/forums.php?action=viewthread&threadid=24013">Read the OP for more information.</a> | |
<span onclick="document.getElementById('content').removeChild(document.getElementById('userscript-highlight-installinfo'));localStorage.setItem('userscript-highlight-installinfo', 'yay');">✖</span>`; | |
userscriptInfo.style.setProperty("border", "1px solid yellow", "important"); | |
userscriptInfo.style.setProperty("padding", "10px", "important"); | |
userscriptInfo.style.setProperty("background", "black", "important"); | |
userscriptInfo.style.setProperty("color", "white", "important"); | |
userscriptInfo.style.setProperty("margin-bottom", "10px", "important"); | |
userscriptInfo.style.setProperty("position", "relative", "important"); | |
content.insertBefore(userscriptInfo, content.children[0]); | |
} | |
const torrents = document.querySelectorAll("a[href*='torrents'][href*='.php?id='][href*='&torrentid=']:not([href*='#']):not([title])"); | |
Array.prototype.forEach.call(torrents, function(element, index) { | |
let link = element.innerHTML; | |
if(link == "[return]") return; | |
link = link.replace("»", "").trim(); | |
link = link.split("] [").join("</span>] [<span>"); | |
link = link.split(" [").join("</span> [<span>"); | |
link = link.split(" - ").join("</span> - <span>"); | |
link = link.split(" | ").join("</span> | <span>"); | |
link = link + "</span>"; | |
link = link.replace("]</span>", "</span>]"); | |
link = link.split(" (").join("</span> (<span>"); | |
link = link.replace(")</span>", "(</span>"); | |
link = link.replace(")</span>", "</span>)"); | |
link = link.replace("(</span>", "</span>)"); | |
link = link.replace("ISO</span> (<span>", "ISO</span> )<span>"); | |
link = link.replace("VOB IFO</span> (<span>", "VOB IFO</span> )<span>"); | |
link = link.replace("M2TS</span> (<span>", "M2TS</span> )<span>"); | |
link = link.replace(" [<span>", " [<span class='userscript-highlight-auto userscript-highlight-year'>"); | |
link = link.replace(" - <span>", " - <span class='userscript-highlight-auto userscript-highlight-type'>"); | |
link = link.replace(" (<span>", " (<span class='userscript-highlight-auto userscript-highlight-group'>"); | |
link = link.replace("<span>ISO</span> )<span>", "<span>ISO</span> (<span class='userscript-highlight-auto userscript-highlight-region'>"); | |
link = link.replace("<span>VOB IFO</span> )<span>", "<span>VOB IFO</span> (<span class='userscript-highlight-auto userscript-highlight-region'>"); | |
link = link.replace("<span>M2TS</span> )<span>", "<span>M2TS</span> (<span class='userscript-highlight-auto userscript-highlight-region'>"); | |
link = link.replace("</span> (<span class='userscript-highlight-auto userscript-highlight-group'>18+)", " (18+)"); | |
link = link.replace("</span> (<span>18+)", " (18+)"); | |
link = "<span>" + link; | |
element.innerHTML = (link.includes(" ") ? link.replace("<span>", "<span class='userscript-highlight-auto userscript-highlight-series'>") : link); | |
element.classList.add("userscript-highlight"); | |
}); | |
Array.prototype.forEach.call(document.querySelectorAll(".userscript-highlight > span"), function(element, index) { | |
let matched = false; | |
const html = element.innerHTML; | |
if(element.classList.contains("userscript-highlight-auto")) { | |
if(html == "Pruned!") { | |
matched = addInfo(element, "pruned"); | |
} else if(html == "Snatched") { | |
matched = addInfo(element, "snatched"); | |
} else { | |
matched = addInfo(element, element.className.split(" userscript-highlight-")[1], html); | |
} | |
element.classList.remove(element.className.split(" ")[1]); | |
} | |
if(["TV", "DVD", "HD DVD", "Blu-ray", "UHD Blu-ray", "VHS", "VCD", "LD", "Web", "CD", "Vinyl", "Soundboard"].indexOf(html) != -1) matched = addInfo(element, "media", html); | |
if(["AVI", "MKV", "MP4", "OGM", "WMV", "MPG", "MPEG", "ISO", "VOB", "VOB IFO", "TS", "M2TS"].indexOf(html) != -1) matched = addInfo(element, "container", html); | |
if(["h264", "h264 10-bit", "h265", "h265 10-bit", "XviD", "DivX", "WMV", "MPEG", "VC-1", "MPEG-TS", "DVD5", "DVD9"].indexOf(html) != -1) matched = addInfo(element, "codec", html); | |
if(["MP3", "Vorbis", "Opus", "AAC", "AC3", "TrueHD", "DTS", "DTS-ES", "FLAC", "PCM", "WMA", "Real Audio", "DTS-HD", "DTS-HD MA"].indexOf(html.substr(0, html.lastIndexOf(" "))) != -1) { matched = addInfo(element, "audioCodec", html.substr(0, html.lastIndexOf(" "))); const audioChannels = html.substr(html.lastIndexOf(" ") + 1); addInfo(element.parentNode, "audioChannels", audioChannels, false); element.outerHTML = element.outerHTML.replace(" " + audioChannels, "</span> <span data-audio-channels='" + audioChannels + "'>" + audioChannels); } | |
if(["RAW", "Hardsubs", "Softsubs"].indexOf(html) != -1) matched = addInfo(element, "subbing", html); | |
if(["AAC", "MP3", "FLAC"].indexOf(html) != -1) matched = addInfo(element, "encoding", html); | |
if(["192", "V2 (VBR)", "256", "V0 (VBR)", "320", "Lossless", "Lossless 24-bit"].indexOf(html) != -1) matched = addInfo(element, "bitrate", html); | |
if(/^\d+x\d+$/.test(html)) matched = addInfo(element, "resolution", html); | |
if(["720p", "1080p", "1080i", "4K"].indexOf(html) != -1) matched = addInfo(element, "resolution", html); | |
if(["4:3", "16:9", "1.85:1", "2.39:1", "2.4:1"].indexOf(html) != -1) matched = addInfo(element, "aspectRatio", html); | |
if(["Raw", "Translated"].indexOf(html.trim()) != -1) matched = addInfo(element, "translation", html.trim()); | |
if(["Archived Scans", "EPUB", "PDF"].indexOf(html) != -1) matched = addInfo(element, "fileType", html); | |
if(["Game", "Patch", "DLC"].indexOf(html) != -1) matched = addInfo(element, "type", html); | |
if(["PC", "PS2", "PSP", "PSX", "GameCube", "Wii", "GBA", "NDS", "N64", "SNES", "NES", "Dreamcast", "PS3", "3DS", "PS Vita"].indexOf(html) != -1) matched = addInfo(element, "platform", html); | |
if(["Region Free", "NTSC-J", "NTSC-U", "PAL", "JPN", "ENG", "EUR"].indexOf(html) != -1) matched = addInfo(element, "region", html); | |
if(["Archived", "Unarchived"].indexOf(html) != -1) matched = addInfo(element, "archived", html); | |
if(html == "Digital") matched = addInfo(element, "digital"); | |
if(html == "Ongoing") matched = addInfo(element, "ongoing"); | |
if(html == "Dual Audio") matched = addInfo(element, "dualAudio"); | |
if(html == '<img src="/static/common/rmstr.png" alt="Remastered" title="This torrent is from a remastered source!">') matched = addInfo(element, "remaster"); | |
if(html == '<img src="/static/common/flicon.png" alt="Freeleech!" title="This torrent is freeleech. Remember to seed!">') matched = addInfo(element, "freeleech"); | |
if(html == '<font color="#990000">Exclusive!</font>') matched = addInfo(element, "exclusive"); | |
if(html == '<img src="/static/common/hentai.png" alt="Hentai" title="This torrent is of uncensored hentai (18+) material!">') matched = addInfo(element, "hentai", "Uncensored"); | |
if(html == '<img src="/static/common/hentaic.png" alt="Hentai" title="This torrent is of censored hentai (18+) material!">') matched = addInfo(element, "hentai", "Censored"); | |
if(html == 'Log') matched = addInfo(element, "log"); | |
if(html == 'Cue') matched = addInfo(element, "cue"); | |
if(html == 'Scene') matched = addInfo(element, "scene"); | |
if(!matched) addInfo(element, "misc", html, false); | |
}); | |
function addInfo(element, name, value = "", parent = true) { | |
element.dataset[name] = value; | |
if(parent) element.parentNode.dataset[name] = value; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment