|
// ==UserScript== |
|
// @name Shiki Custom Search Button |
|
// @namespace http://shikimori.me/ |
|
// @version 0.1 |
|
// @description Добавляет кнопку для поиска аниме\манги на выбранном вами сайте |
|
// @author https://vk.com/xeleos |
|
// @match *://shikimori.org/* |
|
// @match *://shikimori.one/* |
|
// @match *://shikimori.me/* |
|
// @icon https://www.google.com/s2/favicons?domain=shikimori.me |
|
// @license MIT |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
let debug = false; |
|
let site = () => `https://rutracker.org/forum/tracker.php?nm=${escape(getMetaName())}`; |
|
let buttonName = 'Поиск на рутрекере'; |
|
|
|
function log(message) { |
|
if (debug) { |
|
console.log('Shiki Search:\n', message); |
|
} |
|
} |
|
|
|
function getMetaName() { |
|
return document.querySelector("header > meta[itemprop=name]").content; |
|
} |
|
|
|
function appendShikiSearch() { |
|
'use strict'; |
|
|
|
let currentPath = window.location.pathname.substring(0, 7); |
|
if (!(currentPath === "/animes" || currentPath === "/mangas" || currentPath === "/ranobe") || !document.querySelector(".c-info-right")) { |
|
log('Неподходящая страница'); |
|
return; |
|
} |
|
|
|
if (document.querySelector("#shiki-search") !== null) { |
|
log('Уже был создано'); |
|
return; |
|
} |
|
|
|
let shikiSearchEl = document.createElement('div'); |
|
shikiSearchEl.setAttribute('id', 'shiki-search'); |
|
document.querySelector(".scores").appendChild(shikiSearchEl); |
|
|
|
// добавляем данные в аттрибуты для js-событий |
|
const aEl = document.createElement('a'); |
|
aEl.href = site(); |
|
aEl.target = "_blank"; |
|
aEl.textContent = buttonName; |
|
shikiSearchEl.insertAdjacentElement('afterend', aEl); |
|
} |
|
|
|
function ready(fn) { |
|
document.addEventListener('page:load', fn); |
|
document.addEventListener('turbolinks:load', fn); |
|
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") fn(); |
|
else document.addEventListener('DOMContentLoaded', fn); |
|
} |
|
|
|
ready(appendShikiSearch); |