[PSA] Quick Search

It adds PSA quick search buttons for IMDB and Subscene

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         [PSA] Quick Search
// @author       nht.ctn
// @namespace    https://github.com/nhtctn
// @version      1.3
// @description  It adds PSA quick search buttons for IMDB and Subscene
// @icon         https://images2.imgbox.com/26/c1/2OXmz3tN_o.png
// @license      MIT

// @include      *://psa.*/tv-show/*
// @include      *://psa.*/movie/*
// @match        *://subscene.com/subtitles/title?q=*

// @run-at       document-end

// @require	     https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require      https://greasyfork.org/scripts/427315-url-based-search-for-some-websites/code/URL%20Based%20Search%20for%20Some%20Websites.js?version=936416
// ==/UserScript==
/*jshint esversion: 6 */
/* global $ */
(function() {

	'use strict';

	var PlanetDP =
	[
		{psa: '1', movie: '1', tv: '0', name: 'Letterboxd', url_title: 'https://letterboxd.com/search/films/%title%',},
		{psa: '1', movie: '1', tv: '1', name: 'Subscene',   url_title: 'http://subscene.com/subtitles/title?q=%title%',},
		{psa: '1', movie: '1', tv: '1', name: 'IMDb',       url_title: 'https://www.imdb.com/find/?q=%title%',},
	];

	// Common Used Vars
    var pageUrl = window.location.href;
    var titleArea;
    var title;
    var year = "";

	if (pageUrl.search(/psa\..+\/(tv-show|movie)\//) >= 0 && PlanetDP[0].psa == 1 ) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    {
	    const html = () => {
		   var h = '';
		   for( var i = 0, len = PlanetDP.length; i < len; i++ ) {
		    	var p = PlanetDP[i];
                if ( p.psa == 1 && (p.movie == pageUrl.search(/psa\..+\/movie\//) >= 0 || p.tv == pageUrl.search(/psa\..+\/tv-show\//) >= 0) ) {
                    h += '<li class="648search" style="float: right;"><a target="_blank" href="' + url( p.url_title ) + '">' + p.name + '</a></li>';
                }
		    }
		    return h;
	    };

        // Vars
        title = titleEdit( $('article h1.entry-title').text().replace(/ \((\d{4})\)/, "") );
        year = '';
        titleArea = $('div.page-title li.comments');
        titleArea.after( html() );
    }

	function url( site ) {
        if ( site.indexOf( "%title%" ) >= 0) {site = site.replace( /%title%/, title );}
        if ( site.indexOf( "%year%" ) >= 0) {site = site.replace( /%year%/, year );}

		return site;
    }
    function titleEdit( e_title ) {
        e_title = e_title
            .replace( ":", " " )
            .replace( "-", " " )
            .replace("&amp;","&") //replace & with code
            .replace("&nbsp;","") //delete nobreak space
            .replace(/[\/\\#+()$~%"*?<>{}]/g, " ") //remove bad chars
            .replace( /\s{2,}/g, " " )
            .trim()
        ;
        return e_title;
    }
})();