Damezuma / dm-hitomi-loader

// ==UserScript==
// @name dm-hitomi-loader
// @namespace  https://openuserjs.org/users/Damezuma
// @match https://hitomi.la/*
// @description   히토미의 주소를 URI 커스텀으로 바꿔줍니다.
// @copyright     2017, Damezuma (https://openuserjs.org/users/Damezuma)
// @license       MIT; https://opensource.org/licenses/MIT
// @version       0.1.6
// @include       https://www.example.com/*
// @grant none
// ==/UserScript==

// ==OpenUserJS==
// @author Damezuma
// ==/OpenUserJS==
// ==UserScript==

$(window).load(()=>{
  $(".gallery-content").on("DOMSubtreeModified", function(){
    $(".gallery-content>.dj h1 a[href^='/galleries/'], .gallery-content>.manga h1 a[href^='/galleries/'], .gallery-content>.acg h1 a[href^='/galleries/']").each((i, it)=>{
      if($(it).parent().children("button").length != 0)
        return;
      
      let button = document.createElement("button");
      let href = it.href.replace("https://","dm-hitomi://");
      button.addEventListener("click",(e)=>{
        console.log(href);
        document.location = href;
      });

      button.innerText  = "히토미 다운로더로 다운받기";

      it.parentNode.insertBefore(button, it.nextSibling);
      it.parentNode.insertBefore(document.createElement("br"), it.nextSibling);
    });
  });
});
var a = document.querySelector("h1>a[href^='/reader/']");
if(a != null){
	let button = document.createElement("button");
  let href = a.href.replace("https://","dm-hitomi://").replace("reader","galleries");
  button.addEventListener("click",(e)=>{
    console.log(href);
    document.location = href;
  });

  button.innerText  = "히토미 다운로더로 다운받기";

  a.parentNode.insertBefore(button, a.nextSibling);
  a.parentNode.insertBefore(document.createElement("br"), a.nextSibling);
}