Skip to content

Instantly share code, notes, and snippets.

@ivanmem
Last active August 14, 2023 11:09
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 ivanmem/6cd74f957166ef04b271569cad70b427 to your computer and use it in GitHub Desktop.
Save ivanmem/6cd74f957166ef04b271569cad70b427 to your computer and use it in GitHub Desktop.
Добавляет кнопку для поиска аниме\манги на выбранном вами сайте
// ==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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment