Skip to content

Instantly share code, notes, and snippets.

@NuarkNoir
Created August 9, 2019 10:13
Show Gist options
  • Save NuarkNoir/fd14aea6f48a9a5212184cf7460c89d1 to your computer and use it in GitHub Desktop.
Save NuarkNoir/fd14aea6f48a9a5212184cf7460c89d1 to your computer and use it in GitHub Desktop.
Sankaku2Aria - Generates parametrized links, compatible with aria2 (with `-P` parameter)
// ==UserScript==
// @name Sankaku2Aria
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Generates parametrized links, compatible with aria2 (with `-P` parameter)
// @author Nuark
// @match *://sankakucomplex.com/*/*/*/*/
// @match *://www.sankakucomplex.com/*/*/*/*/
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.querySelector(".entry-header").innerHTML += '<div class="entry-meta"><div id="link_holder" class="meta-item">:3</div></div>';
let links = Array.from(new Set(Array.from(document.querySelectorAll(".entry-content [data-lazy-type=\"image\"]")).map(link=>link.parentNode.href)));
let gifs = links.filter(link=>link.endsWith(".gif"));
let rasters = links.filter(link=>link.endsWith(".jpg")||link.endsWith(".jpeg")||link.endsWith(".png"));
console.log(gifs);
console.log(rasters);
let out = "";
if (rasters.length > 0) {
let link = rasters[0];
link = (link.startsWith("https:")? "" : "https:") + link;
console.log(link);
let parts = link.split(/(.*-)(\d+)(\..*)/).slice(1, -1);
out += `${parts[0]}[1-${rasters.length}]${parts[2]}`;
if (gifs.length > 0) {
out += "<br>";
}
}
if (gifs.length > 0) {
let link = gifs[0];
link = (link.startsWith("https:")? "" : "https:") + link;
console.log(link);
let parts = link.split(/(.*-)(\d+)(\..*)/).slice(1, -1);
out += `${parts[0]}[1-${gifs.length}]${parts[2]}`;
}
if (rasters.length === 0 && gifs.length === 0) {
out = "can't obtain links :(";
}
document.querySelector("#link_holder").innerHTML = out;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment