// ==UserScript== // @name Vivo.sx Tools (add hash to url, show link) // @version 1.1 // @grant none // @include https://vivo.sx/* // @include https://bs.to/* // ==/UserScript== if (document.location.host == "vivo.sx") { initVivoScript(); } else if (document.location.host == "bs.to") { initBsScript(); } function initVivoScript() { if(!document.location.href.match("#")){ document.location.href = document.location.href + "#123456789"; } let videoContainer = Q(".stream-content video"); let videoFooter = Q(".stream-share"); if (!videoContainer) console.warn("[VSXTools] Video container not found"); if (!videoFooter) console.warn("[VSXTools] Video footer not found"); if (videoContainer && videoFooter) { console.info("[VSXTools] Adding link text box"); let toolContainer = document.createElement("DIV"); toolContainer.style = "display: flex; padding: 4px;"; let inputVideoTitle = document.createElement("INPUT"); inputVideoTitle.setAttribute("readonly", "readonly"); inputVideoTitle.classList.add("form-control"); inputVideoTitle.style = "margin-right: 4px; width: 60%;"; inputVideoTitle.value = "..."; inputVideoTitle.style.display = "none"; inputVideoTitle.style.cursor = "unset"; let inputVideoUrl = document.createElement("INPUT"); inputVideoUrl.setAttribute("readonly", "readonly"); inputVideoUrl.classList.add("form-control"); inputVideoUrl.value = "...";; let buttonCopyTitle = document.createElement("BUTTON"); buttonCopyTitle.classList.add("btn"); buttonCopyTitle.classList.add("btn-primary"); buttonCopyTitle.style = "margin-left: 4px;"; buttonCopyTitle.innerText = "Copy Title"; buttonCopyTitle.style.display = "none"; buttonCopyTitle.onclick = function() { inputVideoTitle.select(); document.execCommand("copy"); }; let buttonVideoNewTab = document.createElement("BUTTON"); buttonVideoNewTab.classList.add("btn"); buttonVideoNewTab.classList.add("btn-primary"); buttonVideoNewTab.style = "margin-left: 4px;"; buttonVideoNewTab.innerText = "Open"; buttonVideoNewTab.setAttribute("disabled", "disabled"); buttonVideoNewTab.onclick = function() { window.open(inputVideoUrl.value); }; let buttonDownload = document.createElement("BUTTON"); buttonDownload.classList.add("btn"); buttonDownload.classList.add("btn-primary"); buttonDownload.style = "margin-left: 4px;"; buttonDownload.innerText = "Download"; buttonDownload.setAttribute("disabled", "disabled") toolContainer.appendChild(inputVideoTitle); toolContainer.appendChild(inputVideoUrl); toolContainer.appendChild(buttonCopyTitle); toolContainer.appendChild(buttonVideoNewTab); //toolContainer.appendChild(buttonDownload); //does not work with popup blocker videoFooter.parentElement.insertBefore(toolContainer, videoFooter); let videoTitle = null; try { let titleQuery = new URLSearchParams(window.location.search).get('title'); if (titleQuery) { videoTitle = titleQuery; inputVideoTitle.value = videoTitle; inputVideoTitle.style.display = ""; buttonCopyTitle.style.display = ""; } } catch(e) {} setTimeout(function(){ //videoContainer needs to be refreshed let videoData = getVideoData(); let url = videoData.url; if (videoData.name != null) { let querySeparator = "?"; if (videoData.url.includes("?")) querySeparator = "&"; videoData.url += querySeparator + "filename=" + videoData.name; if (videoTitle) { videoData.url += "&title=" + encodeURIComponent(videoTitle); } else { videoTitle = videoData.name; inputVideoTitle.value = videoTitle; inputVideoTitle.style.display = ""; buttonCopyTitle.style.display = ""; } } //buttonDownload.setAttribute("download", "test"); buttonDownload.onclick = function() { document.location.href = videoData.url; console.info(videoData.url); }; inputVideoUrl.value = videoData.url; inputVideoUrl.style = "cursor: unset;"; if (videoData.url != "null") { buttonVideoNewTab.removeAttribute("disabled"); buttonDownload.removeAttribute("disabled"); } }, 1000); } function getVideoData() { let url = Q(".stream-content video").getAttribute("src") || Q(".stream-content video source").getAttribute("src") || "null"; let name = null; if (url != "null") { let videoFrame = Q(".stream-content"); if (videoFrame) { let titleAttr = videoFrame.getAttribute("data-name"); if (titleAttr) { name = titleAttr; } } } return { url: url, name: name }; } } function initBsScript() { let lastTitle = null; setInterval(function(){ let titleHeading = Q("#root h2:first-of-type"); if (titleHeading && titleHeading.childNodes.length > 0) { let title = titleHeading.childNodes[0].textContent.trim(); let seasonButton = Q("#seasons .active a"); let season = null; if (seasonButton) { season = seasonButton.textContent.trim(); } let episodeButton = Q("#episodes .active a"); let episode = null; if (episodeButton) { episode = episodeButton.textContent.trim(); } let episodeTitleHeading = Q("#root .episode h2:first-of-type"); if (episodeTitleHeading) { let episodeTitle = episodeTitleHeading.textContent.trim(); if (season != null && episode != null) { title += " S" + season.padStart(2, "0") + "EP" + episode.padStart(2, "0") + " " + episodeTitle; } else { title += " - " + episodeTitle; } } let videoLink = Q(".hoster-player a"); if (videoLink) { if (title != lastTitle){ console.log(title + " - " + videoLink.href); videoLink.href += (videoLink.href.includes("?") ? "&" : "?") + "title=" + encodeURIComponent(title); videoLink.style.color = "#10C070"; let titleDiv = document.createElement("div"); titleDiv.style["font-size"] = "0.75em"; titleDiv.innerText = title; videoLink.appendChild(titleDiv); } lastTitle = title; } } }, 500); } function Q(selector){ return document.querySelector(selector); }