Last active
February 9, 2018 14:11
-
-
Save neko-neko-nyan/a4db87b942927ad473543ba6f60cec33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Alt Watcher | |
// @namespace https://vk.com/shiki_ex | |
// @version 1.2.0 | |
// @description [shikimori.org] Добавляет ссылку на Альтернативные сайты просмотра аниме ### | |
// @author STorn | |
// @match https://shikimori.org/* | |
// @match http://shikimori.org/* | |
// @require https://code.jquery.com/jquery-3.3.1.slim.min.js | |
// @grant none | |
// @license MIT | |
// @copyright 2018, Newt300 (https://openuserjs.org/users/Newt300) | |
// ==/UserScript== | |
// url, name, allowed page types (bit 0 - blocked, 1 - hentai) | |
var selections = [ | |
["https://smotret-anime.ru/catalog/search?q=", "Anime 365", 1], | |
["https://hentai365.ru/catalog/search?q=", "Hentai 365", 2], | |
["https://vk.com/video?q=", "VK", 3], | |
["https://sovetromantica.com/anime?query=", "SR", 1], | |
]; | |
var $ = jQuery.noConflict(true); | |
function getPrefService(pageType) { | |
var matches = document.cookie.match(new RegExp('(?:^|; )altWatcherPrefServiceFor' + pageType + '=([^;]*)')); | |
if (matches){ | |
matches = decodeURIComponent(matches[1]); | |
matches = selections.find(function(it){ | |
return it[1] == matches; | |
}); | |
if (matches && matches[2] & pageType) return matches; | |
} | |
for (var i = 0, v = selections[i]; i < selections.length; v = selections[++i]) | |
if ((v[2] & pageType) != 0) | |
return v; | |
return selections[0]; | |
} | |
function setPrefService(pageType, value) { | |
var d = new Date(); | |
d.setTime(d.getTime() + 666 * 1000); | |
document.cookie = "altWatcherPrefServiceFor" + pageType + "=" + encodeURIComponent(value) + "; path=/; expires=" + d.toUTCString(); | |
} | |
function start(){ | |
if (window.location.pathname.indexOf("animes") && ($(".disabled").length || !$(".watch-online-placeholer").children().length)) { | |
var animeName = $("#animes_show > section > div > header > h1").text().split(" / ")[1], | |
link = $('<a target="_blank"/>'), | |
bar = $('<div/>'), | |
pageType = (!!$(".is-censored").length + 1), | |
barItemClicked = function (){ | |
var i = selections[$(this).data('service-index')]; | |
link.attr('href', i[0] + animeName).text('Смотреть на ' + i[1]); | |
setPrefService(pageType, i[1]); | |
bar.hide(); | |
}; | |
for (var i = 0; i < selections.length; i++) { | |
var v = selections[i]; | |
if ((v[2] & pageType) != 0) | |
bar.append($('<a/>').addClass('b-link_button dark watch-online').text(v[1]).data('service-index', i).click(barItemClicked)); | |
} | |
i = getPrefService(pageType); | |
$(".watch-online-placeholer").empty().append( | |
$('<div/>').addClass('watch-online').append( | |
link.addClass("b-link_button dark").css({float: 'left', width: "calc(100% - 31px)"}) | |
.attr('href', i[0] + animeName).text('Смотреть на ' + i[1]) | |
).append( | |
$('<a/>').addClass("b-link_button dark").css({width: "31px", float: 'right', heigth: '31px'}).text('▼').click(function(){ | |
bar.toggle(); | |
}) | |
).append($('<div/>').addClass('clearfix')) | |
).append(bar.addClass('block').hide()); | |
} | |
} | |
$(document).ready(start); | |
$(document).on('page:load', start); | |
$(document).on('turbolinks:load', start); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment