Skip to content

Instantly share code, notes, and snippets.

@DogmaDragon
Created September 4, 2023 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DogmaDragon/fb3ed033c0d1f0a6811137dfea0c4ce8 to your computer and use it in GitHub Desktop.
Save DogmaDragon/fb3ed033c0d1f0a6811137dfea0c4ce8 to your computer and use it in GitHub Desktop.
Userscript for Stash
// ==UserScript==
// @name Stash Video Compare Userscript
// @description Userscript for Stash
// @match *localhost:9999/*
// @grant GM_openInTab
// @require https://code.jquery.com/jquery-1.12.4.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version 1.0
// @author Scruffynerf
// ==/UserScript==
(function() {
'use strict';
console.log('Script Stash initialize');
waitForKeyElements(".navbar-brand", addbutton);
function addbutton() {
const navBar = document.querySelector(".navbar-nav");
const buttonClass = navBar.firstChild.attributes.class.value;
const linkClass = navBar.firstChild.firstChild.attributes.class.value;
const newButton = document.createElement("div");
newButton.setAttribute("class", buttonClass);
newButton.onclick = compare
const innerLink = document.createElement("a");
innerLink.setAttribute("class", linkClass);
const buttonLabel = document.createElement("span");
buttonLabel.innerText = "Video Compare";
innerLink.appendChild(buttonLabel);
newButton.appendChild(innerLink);
navBar.appendChild(newButton);
}
function compare() {
var numberOfChecked = document.querySelectorAll('input[type="checkbox"]:checked').length;
if (numberOfChecked == 2) {
const r = /[^"]+\/scene\/\d+\/s/ms;
var lr = []
const list = document.querySelectorAll('input[type=checkbox]:checked')
for (let item of list) {
var urlstuff = item.nextElementSibling.innerHTML
var m = r.exec(urlstuff)
lr.push(m[0])
}
var site = "http://scruffynerf.stashapp.cc"
var url = site.concat("?leftVideoUrl=", lr[0], "tream&rightVideoUrl=", lr[1], "tream")
GM_openInTab(url, true);
}
}
})();
@AnonTester
Copy link

AnonTester commented Apr 30, 2024

as this doesn't work in the sceneDuplicateChecker admin tool page, I've added a second layout for this and also disabled the help popup. This would be better as an actual plugin for stash incorporating https://github.com/vivictorg/vivict to run without internet access and even better as a modal on the page rather than fullscreen, but I have no idea how to implement that.

Might this is of use to someone.

function compare() {
    if (window.location.pathname == "/sceneDuplicateChecker") {
      var numberOfChecked = document.querySelectorAll('input.position-static[type="checkbox"]:checked').length;
      if (numberOfChecked == 2) {
        var lr = []
        const list = document.querySelectorAll('input[type="checkbox"].position-static:checked')
        for (let item of list) {
          const row = item.closest('tr');
          const nextAnchor = row.querySelector('a');
          const url = nextAnchor.getAttribute('href').replace(/\/scenes\//g, '/scene/')
          lr.push(window.location.origin.concat(url))
        }
        var site = "http://scruffynerf.stashapp.cc"
        var url = site.concat("?leftVideoUrl=", lr[0], "/stream&rightVideoUrl=", lr[1], "/stream&hideHelp=1")
        GM_openInTab(url, true);
      }
    } else {
      var numberOfChecked = document.querySelectorAll('input[type="checkbox"]:checked').length;
      if (numberOfChecked == 2) {
        const r = /[^"]+\/scene\/\d+\/s/ms;
        var lr = []
        const list = document.querySelectorAll('input[type=checkbox]:checked')
        for (let item of list) {
          var urlstuff = item.nextElementSibling.innerHTML
          var m = r.exec(urlstuff)
          lr.push(m[0])
        }
        var site = "http://scruffynerf.stashapp.cc"
        var url = site.concat("?leftVideoUrl=", lr[0], "tream&rightVideoUrl=", lr[1], "tream&hideHelp=1")
        GM_openInTab(url, true);
      }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment