Raw Source
Joeviocoe / StartPage

// ==UserScript==
// @name         StartPage
// @namespace
// @version      1.4
// @description  Skip redirection URL on Google search results.
// @include      *startpage.com/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @updateURL    https://openuserjs.org/install/Joeviocoe/Startpage.user.js
// @downloadURL  https://openuserjs.org/install/Joeviocoe/Startpage.user.js
// @icon         https://www.startpage.com/favicon.ico
// @copyright    2018+, Joeviocoe
// @license      MIT

// @noframes
// ==/UserScript==
// Copyright (c) 2018, Joeviocoe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// * Neither the name of Joeviocoe nor the names of its contributors
//   may be used to endorse or promote products derived from this software
//   without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/*jslint browser: true*/
/*global $, jQuery, alert*/


(function() {
    'use strict';
    var counter = 0, el = $(window), lastY = el.scrollTop();

    function adremove() {
        $('iframe#master-1').parents('section').remove();
        $('a.header__logo').remove();
        $('div.hamburger-menu-container').remove();
        $('div#spon-results').remove();
        $('section.promotion.card.search-item').remove();
    }

    function results() {
        var options = $('ul.search-options__list').not('.list-inline');
        $('div.search-options__modular-content[m!="1"]').attr("m",1).attr("data-show-filters","true").appendTo(options);
        $('li.search-options__list-item--filter-item').remove();
        var query = $('input#query').val();
        var count = $('p.search-options__count[q!="1"]').attr("q",1);
        count.css('opacity','20').css('font-size','10px').css('transform','translateY(25px)').html(count.text()+"<p>:  <u>"+query+"</u></p>");
        $('a.search-result__proxy-links-item[u!="1"],a.w-gl__anonymous-view-url[u!="1"]').attr("u",1).text("ρ").css('margin-left','20px').css("font-size","10px").css("opacity","0.25").each(function() {
            $(this).clone().addClass('wayback').insertAfter( $(this) ).text("α");
        });
        $('a.wayback').each(function() {
            var url = $(this).parents('.search-result__proxy-links').siblings('.search-item__url').text() || $(this).siblings('a.w-gl__result-url').attr('href');
            $(this).attr('href','https://web.archive.org/web/*/'+url);
        });
        $('p.search-options__count').css('pointer-events','all');
        $('.search-item__sub-title').css('display','block');
        $('a.w-gl__result-url').each(function() {
            $(this).text($(this).attr('href'));
        });
        $('span.text-ellipsis').removeClass('text-ellipsis');
    }

    function images() {
        $('a.image-result__proxy-link[u!="1"]').attr("u",1).text("ρ").css("font-size","20px");
        $('a.button[href*="show_picture"][u!="1"]').attr("u",1).text("view through ρroxy").css("font-size","20px");
        $('img[data-image-result-overlay-image][u!="1"]').attr("u",1).removeAttr('onerror').each(function(){
            var proxyurl = decodeURIComponent($(this).clone().attr('data-src'));
            var directurl = 'http' + proxyurl.split('http')[2].split('&sp=')[0];
            $(this).parent('a').attr('href',directurl);
        });
    }

    function header() {
        var currY = el.scrollTop();
        if ( currY > lastY) {
            $('header.header').slideUp();
            lastY = currY - 100;
        } else {
            $('header.header').slideDown();
            lastY = currY + 100;
        }
    }

    function run() {
        adremove();
        results();
        images();
        header();
    }

    console.clear();
    window.addEventListener('click', function() {
        if ( counter === 0 ) {
            setTimeout (function() { run(); counter = 0; }, 500);
        }
        counter++;
    });
    window.addEventListener('scroll', function() {
        if ( counter === 0 ) {
            setTimeout (function() { run(); counter = 0; }, 500);
        }
        counter++;
    });

    counter = 0;
    run();

})();