// ==UserScript== // @name Anime-Loads Title Generator // @version 3.0 // @grant none // @include https://www.anime-loads.org/media/* // ==/UserScript==
var mainDiv = document.getElementById("main");
if(mainDiv){
var styleLib = `
.altg_panel {
position: absolute;
display: block;
top: 70px;
left: -128px;
color: #337ab7;
}
.altg_panel > * {
max-width: 128px;
padding: 10px 15px;
margin-bottom: 10px; background: white; border: 1px solid #337ab7; border-right: none; border-radius: 4px; border-top-right-radius: 0; border-bottom-right-radius: 0; -webkit-user-select: none; user-select: none; }
.altg_panel > *:last-child {
margin-bottom: 0;
}
top: 20px;
position: absolute;
width: calc(100% - 40px);
border: 1px solid black;
background: white; border-radius: 4px;
z-index: 1000;
}
margin-left: 10px;
font-weight: bold;
}
font-size: 1.5em;
}
margin: 10px;
}
`;
var pluginStyle = document.createElement("style"); pluginStyle.innerHTML = styleLib; document.head.appendChild(pluginStyle);
var pluginButtonPanel = document.createElement("DIV"); pluginButtonPanel.className = "altg_panel"; mainDiv.appendChild(pluginButtonPanel);
var generateButton = document.createElement("DIV"); generateButton.innerText = "Generate Titles"; pluginButtonPanel.appendChild(generateButton); generateButton.onclick = function(){generate(false)};
var generateButton2 = document.createElement("DIV"); generateButton2.innerText = "Generate Titles (/w Name)"; pluginButtonPanel.appendChild(generateButton2); generateButton2.onclick = function(){generate(true)};
var generateButton3 = document.createElement("DIV"); generateButton3.innerText = "Generate Titles (/w min Name)"; pluginButtonPanel.appendChild(generateButton3); generateButton3.onclick = function(){generate(true, ":")};
}
function generate(withText, shortNameSeparator){
var popupOld = document.getElementById("altg_popup");
if(popupOld){
popupOld.parentNode.removeChild(popupOld);
return;
}
var selectedReleaseContainer = document.querySelector(".panel-body .tab-content .active .active .episodes"); //content panel -> download/stream (active tab) -> release (active tab) -> episode list let linkContainer = selectedReleaseContainer || document.querySelector("#downloads_episodes_1") || document.querySelector("#streams_episodes_1"); console.debug("Using link container:"); console.debug(linkContainer); var links = linkContainer.getElementsByTagName("a"); var titles = [];
console.log(links);
for (var i = 0; i < links.length; i++) { var link = links[i]; var attribute = link.getAttribute("data-loop"); //0..n
if (attribute != null && !isNaN(attribute)) {
var names = link.children.item(0); //a span
var titleFull = names.getAttribute("title");
if (titleFull != null) {
titles.push(titleFull);
} else {
var title = names.innerHTML.match("[0-9 ]*<\\/strong>\\s*(.*)");//("[0-9 ]*<\\/strong>[ ]*([A-Za-zÄ-Üä-üß0-9 \\?!\\/\\-\\+\\_\\*\"\\.:;,…\\\\(\\)&']*)");
if (title != null && title[1] != null){
titles.push(title[1]);
}
} //titles.push(names.attributes.length >= 2 ? names.attributes[1].name + "=" + names.attributes[1].value : "n/a");
}
}
if (titles.length > 0){ var seriesname = document.getElementsByClassName("page-header")[0].getElementsByTagName("h1")[0].title;
seriesname = extractShortName(seriesname, shortNameSeparator);
var data = '';
data += '' + seriesname + '';
for (var k = 0; k < titles.length; k++) {
data += '' + (withText == true ? "" + seriesname + " Episode " + (k+1) + " - " : "") + extractShortName(titles[k], shortNameSeparator, true) + '';
if (k + 1 < titles.length)
data += '';
}
data += "";
//var newDoc = window.open('', 'wnd');
//newDoc.onload = function(){
//newDoc.document.head.innerHTML = document.head.innerHTML;
//newDoc.document.head.getElementsByTagName("title")[0].innerHTML = "GET-EP v2.1";
//newDoc.document.body.innerHTML = data;
//};
//newDoc.focus();
var popup = document.createElement("DIV");
popup.id = "altg_popup";
popup.innerHTML = data;
mainDiv.appendChild(popup);
}
}
function extractShortName(name, separator, skipFirst){ if (separator != null){ let seperatorIndex = name.indexOf(separator); if (seperatorIndex >= 0){ if (skipFirst === true){ name = name.substr(seperatorIndex + 1).trim(); }else{ name = name.substr(0, seperatorIndex); } } } return name; }
setInterval(function(){ let stupidScripts = document.querySelectorAll("script[src='https://undefined']"); for(let s of stupidScripts){ try { s.remove(); }catch(ignore){ } } }, 1000);