// ==UserScript==
// @name Link Guru
// @namespace http://greasyfork.org/users/2240-doodles
// @author Doodles
// @version 2
// @description Adds boxes full on links to a few sites.
// @include *://*.wikipedia.org/*
// @include *://www.google.*/search?*
// @include *://*.wiktionary.org/wiki/*
// @include *://www.imdb.com/*
// @include *://www.rottentomatoes.com/*
// @run-at document-end
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js
// @grant GM_getValue
// @grant GM_setValue
// @updateVersion 2
// @downloadURL none
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
$(document).ready(function () {
'use strict';
// =======================================================================================================================
String.prototype.lgReplaceAll = function(f, r) {
return this.split(f).join(r);
}
function UrlContains(urlfragment) {
return document.URL.indexOf(urlfragment) != -1;
}
function SelectiveFire(functionToFire, delay){
delay = delay || 2500;
document.body.addEventListener("DOMSubtreeModified", function(){
setTimeout(function() {
functionToFire();
}, delay);
});
functionToFire();
}
function CreateLink(givenLink, urlfragment, linkStyle) {
var linkElement = $('');
$(linkElement).attr('title', givenLink[0]);
$(linkElement).attr('href', givenLink[1] + urlfragment + givenLink[2]);
if(linkStyle != 1){
$('
').attr('src', givenLink[3]).attr('alt', givenLink[0]).appendTo(linkElement);
}
if(linkStyle != 0){
$('').text(givenLink[0]).appendTo(linkElement);
}
return linkElement;
}
function CreateLinkContainer(linkList, urlfragment, linkStyle, newTab) {
var linkContainter = $('
Settings changes do not immediately take effect. A refresh is required.
' +
'');
$("#lgSettingsTabs").tabs();
$('#lgSettingsDialog').dialog({ modal:true, resizable: false, autoOpen: false, width: 634, position: { my: "center top", at: "center top+120", of: window } });
var settingsLink = $('
Link Guru Settings');
$(settingsLink).click(function() {$('#lgSettingsDialog').dialog('open');});
// =======================================================================================================================
// Stored Data Variables
function SetupBoolVariable(_variableIndex, _defaultValue) {
lgSettings[_variableIndex] = GM_getValue(_variableIndex, _defaultValue);
$("#lgSet" + _variableIndex).prop('checked', lgSettings[_variableIndex]).change(function() {
lgSettings[_variableIndex] = this.checked ? true : false;
GM_setValue(_variableIndex, lgSettings[_variableIndex]);
});
}
function SetupRadioVariable(_variableIndex, _variableMax) {
lgSettings[_variableIndex] = GM_getValue(_variableIndex, 0);
$("input[name='lgSet" + _variableIndex + "'][value='"+lgSettings[_variableIndex]+"']").prop('checked', true);
$("input[name='lgSet" + _variableIndex + "']").change(function() {
lgSettings[_variableIndex] = $(this).filter(':checked').val();
GM_setValue(_variableIndex, lgSettings[_variableIndex]);
});
}
var lgSettings = [];
SetupBoolVariable('WikipediaEnabled', true);
SetupBoolVariable('WiktionaryEnabled', true);
SetupBoolVariable('RottenEnabled', true);
SetupBoolVariable('ImdbEnabled', true);
SetupBoolVariable('GoogleEnabled', true);
SetupBoolVariable('WikipediaNewtab', false);
SetupBoolVariable('WiktionaryNewtab', false);
SetupBoolVariable('RottenNewtab', false);
SetupBoolVariable('ImdbNewtab', false);
SetupRadioVariable('WikipediaStyle', 2);
SetupRadioVariable('WiktionaryStyle', 2);
SetupRadioVariable('RottenStyle', 2);
SetupRadioVariable('ImdbStyle', 2);
SetupBoolVariable('GoogleDefinition', true);
var links = [];
// =======================================================================================================================
// WIKIPEDIA
if (UrlContains('wikipedia.org') && window.top == window.self) {
links.push(["Google", "Google search for {{PARAM}}", "http://www.google.com/search?output=search&q={{PARAM}}", "Ocn9d7X.png"]);
links.push(["Google Image", "Google Image search for {{PARAM}}", "http://www.google.com/search?tbm=isch&q={{PARAM}}", "FFntMod.png"]);
links.push(["YouTube", "YouTube search for {{PARAM}}", "https://www.youtube.com/results?search_query={{PARAM}}", "Oi6BUxD.png"]);
if($("ul > li > a.external[href*='www.imdb.com']").length){
links.push(["IMDb", "IMDb page for {{PARAM}}", $("ul > li > a.external[href*='www.imdb.com']").attr('href'), "At43y4m.png"]);
}else{
links.push(["IMDb", "IMDb search for {{PARAM}}", "http://www.imdb.com/find?s=all&q={{PARAM}}", "At43y4m.png"]);
}
if($("a[href='/wiki/Portal:Anime_and_Manga']").length){
links.push(["MyAnimeList", "MyAnimeList search for {{PARAM}}", "https://myanimelist.net/search/all?q={{PARAM}}", "dm777Ul.png"]);
}
links.push(["Pirate Bay", "The Pirate Bay search for {{PARAM}}", "https://thepiratebay.se/search/{{PARAM}}/0/99/0", "cnc2XKT.png"]);
links.push(["Imgur", "Imgur search for {{PARAM}}", "http://imgur.com/search?q={{PARAM}}", "bMdIHrQ.png"]);
links.push(["Last.fm", "Last.fm search for {{PARAM}}", "http://www.last.fm/search?q={{PARAM}}&type=track", "ntoVbxe.png"]);
$('#p-navigation > div.body > ul').append($('
').append(settingsLink));
if (lgSettings['WikipediaEnabled'] && !UrlContains('/wiki/Main_Page') && !UrlContains('/wiki/Portal:') && !UrlContains('/wiki/Talk:') && $('h1#firstHeading') && $('li#ca-nstab-main.selected')) {
var pageTitle = $('h1#firstHeading').text();
pageTitle = pageTitle.lgReplaceAll("
", "").lgReplaceAll("", "");
pageTitle = pageTitle.lgReplaceAll("=", "%3D").lgReplaceAll("=", "%3D").lgReplaceAll("=", "%3D");
pageTitle = pageTitle.lgReplaceAll("&", "%26").lgReplaceAll("&", "%26").lgReplaceAll("&", "%26");
pageTitle = pageTitle.replace(" (film)","").replace("(film)","").replace(" film)",")");
$(CreateLinkContainer(links, pageTitle, lgSettings['WikipediaStyle'], lgSettings['WikipediaNewtab'])).insertBefore('h1#firstHeading');
$('div#lgLinkContainer').css({'float':'right', 'padding':'10px 0 10px 0'});
if ($('div.mw-indicators').children().length > 0) {
$('div.mw-indicators').css({'padding-left':'25px'});
}
}
}
// =======================================================================================================================
// WIKTIONARY
if (UrlContains('wiktionary.org') && window.top == window.self) {
links.push(["Merriam-Webster", "Merriam-Webster Dictionary and Thesaurus", "http://www.merriam-webster.com/dictionary/{{PARAM}}", "3IkK6gI.png"]);
links.push(["Thesaurus.com", "Thesaurus.com", "http://thesaurus.com/browse/{{PARAM}}", "Ngxbqzc.png"]);
links.push(["Google", "Google search for define:{{PARAM}}", "http://www.google.com/search?output=search&q=define:{{PARAM}}", "Ocn9d7X.png"]);
links.push(["Synonym.com", "Synonym.com", "http://www.synonym.com/synonyms/{{PARAM}}/", "5zx9OP9.png"]);
links.push(["Wikisaurus", "Wikisaurus", "http://wiktionary.org/wiki/Wikisaurus:{{PARAM}}", "2wDa3Kq.png"]);
links.push(["One Look", "One Look", "http://www.onelook.com/?w={{PARAM}}&ls=a", "GjvfCVA.png"]);
links.push(["Wolfram|Alpha", "Wolfram|Alpha", "http://www.wolframalpha.com/input/?i={{PARAM}}", "z5p7oL7.png"]);
links.push(["Urban Dictionary", "Urban Dictionary", "http://www.urbandictionary.com/define.php?term={{PARAM}}", "oRspJNs.png"]);
links.push(["iTools", "iTools", "http://itools.com/language/dictionary?q={{PARAM}}&submit=English+Dictionary", "caWzb02.png"]);
links.push(["Vocabulary.com", "Vocabulary.com Dictionary", "http://www.vocabulary.com/dictionary/{{PARAM}}", "8MNsoze.png"]);
links.push(["Cambridge", "Cambridge Dictionary", "http://dictionary.cambridge.org/dictionary/english/{{PARAM}}", "MtWE6Yt.png"]);
links.push(["RhymeZone", "RhymeZone", "http://www.rhymezone.com/r/rhyme.cgi?Word={{PARAM}}&typeofrhyme=perfect&org1=syl&org2=l&org3=y", "d9giQh4.png"]);
links.push(["Online Etymology", "Online Etymology Dictionary", "http://www.etymonline.com/index.php?search={{PARAM}}", "uUiJWbY.png"]);
links.push(["howjsay", "howjsay: Online Dictionary of English Pronunciation", "http://howjsay.com/pronunciation-of-{{PARAM}}", "lrHhN0J.png"]);
$('#p-navigation > div.body > ul').append($('
').append(settingsLink));
if (lgSettings['WiktionaryEnabled'] && !UrlContains('/wiki/Wiktionary:Main_Page') && !UrlContains('/wiki/Index:') && !UrlContains('/wiki/Talk:') && !UrlContains('/wiki/Special:') &&
!UrlContains('/wiki/Category:') && $('h1#firstHeading') && $('li#ca-nstab-main.selected')) {
var pageTitle = $('h1#firstHeading').text().lgReplaceAll("
", "").lgReplaceAll("", "");
$(CreateLinkContainer(links, pageTitle, lgSettings['WiktionaryStyle'], lgSettings['WiktionaryNewtab'])).insertBefore('h1#firstHeading');
$('div#lgLinkContainer').css({'float':'right', 'padding':'10px 0 10px 0'});
}
}
// =======================================================================================================================
// Rotten Tomatoes
if (UrlContains('www.rottentomatoes.com') && window.top == window.self) {
$('div.header_links').prepend(settingsLink);
if (lgSettings['RottenEnabled']) {
if(UrlContains("rottentomatoes.com/m/")){
links.push(["YouTube", "YouTube search for {{PARAM}} trailer", "http://www.youtube.com/results?search_query={{PARAM}} trailer", "Oi6BUxD.png"]);
links.push(["Google Image", "Google Image search for {{PARAM}}", "http://www.google.com/search?tbm=isch&q={{PARAM}}", "FFntMod.png"]);
links.push(["Google", "Google search for {{PARAM}}", "http://www.google.com/search?output=search&q={{PARAM}}", "Ocn9d7X.png"]);
links.push(["Wikipedia", "Wikipedia search for {{PARAM}}", "http://en.wikipedia.org/w/index.php?title=Special:Search&search={{PARAM}}", "8GnE9TT.png"]);
links.push(["IMDb", "IMDb search for {{PARAM}}", "http://www.imdb.com/find?s=all&q={{PARAM}}", "At43y4m.png"]);
links.push(["MetaCritic", "MetaCritic search for {{PARAM}}", "http://www.metacritic.com/search/all/{{PARAM}}/results", "j84MuyF.png"]);
links.push(["AllMovie", "AllMovie search for {{PARAM}}", "http://www.allmovie.com/search/movies/{{PARAM}}", "893QQhS.png"]);
links.push(["Box Office Mojo", "Box Office Mojo search for {{PARAM}}", "http://www.boxofficemojo.com/search/?q={{PARAM}}", "GLa3QlT.png"]);
links.push(["Movie Mistakes", "Movie Mistakes search for {{PARAM}}", "http://www.moviemistakes.com/search.php?text={{PARAM}}", "DNn1W4y.png"]);
links.push(["Letterboxd", "Letterboxd search for {{PARAM}}", "http://letterboxd.com/search/{{PARAM}}/", "BnJx4gH.png"]);
links.push(["Pirate Bay", "The Pirate Bay search for {{PARAM}}", "http://thepiratebay.org/search/{{PARAM}}/0/99/200", "cnc2XKT.png"]);
links.push(["YIFY Subtitles", "YIFY Subtitles search for {{PARAM}}", "http://www.yifysubtitles.com/search?q={{PARAM}}", "VyMFcXf.png"]);
links.push(["Imgur", "Imgur search for {{PARAM}}", "http://imgur.com/search?q={{PARAM}}", "bMdIHrQ.png"]);
var titleText = $('h1.title.hidden-xs').html().split("
1){
var titleText = $('h1.movie_title').html().split(" h1').text();
$(CreateLinkContainer(links, titleText, lgSettings['RottenStyle'], lgSettings['RottenNewtab'])).appendTo('div.celeb_name');
$('div.celeb_name > h1').css({'border-bottom':'none', 'margin-bottom':'0', 'padding-bottom':'0'});
}
}
}
// =======================================================================================================================
// IMDb
if (UrlContains('www.imdb.com') && window.top == window.self) {
$(settingsLink).css({'color':'white'});
$('').css({'font-size':'10px', 'height':'15px', 'line-height':'15px', 'padding-left':'3px' }).append(settingsLink).prependTo('div#nb20');
$('div#navbar').css({'margin-top':'0'});
if (lgSettings['ImdbEnabled']) {
if(UrlContains("/title/")){
links.push(["YouTube", "YouTube search for {{PARAM}} tralier", "http://www.youtube.com/results?search_query={{PARAM}} trailer", "Oi6BUxD.png"]);
links.push(["Google Image", "Google Image search for {{PARAM}}", "http://www.google.com/search?tbm=isch&q={{PARAM}}", "FFntMod.png"]);
links.push(["Google", "Google search for {{PARAM}}", "http://www.google.com/search?output=search&q={{PARAM}}", "Ocn9d7X.png"]);
links.push(["Wikipedia", "Wikipedia search for {{PARAM}}", "http://en.wikipedia.org/w/index.php?title=Special:Search&search={{PARAM}}", "8GnE9TT.png"]);
links.push(["Rotten Tomatoes", "Rotten Tomatoes search for {{PARAM}}", "http://www.rottentomatoes.com/search/?search={{PARAM}}&sitesearch=rt", "KdEB9NR.png"]);
links.push(["MetaCritic", "MetaCritic search for {{PARAM}}", "http://www.metacritic.com/search/all/{{PARAM}}/results", "j84MuyF.png"]);
links.push(["AllMovie", "AllMovie search for {{PARAM}}", "http://www.allmovie.com/search/movies/{{PARAM}}", "893QQhS.png"]);
links.push(["Box Office Mojo", "Box Office Mojo search for {{PARAM}}", "http://www.boxofficemojo.com/search/?q={{PARAM}}", "GLa3QlT.png"]);
links.push(["Movie Mistakes", "Movie Mistakes search for {{PARAM}}", "http://www.moviemistakes.com/search.php?text={{PARAM}}", "DNn1W4y.png"]);
links.push(["Letterboxd", "Letterboxd search for {{PARAM}}", "http://letterboxd.com/search/{{PARAM}}/", "BnJx4gH.png"]);
links.push(["Episode Calendar", "Episode Calendar search for {{PARAM}}", "http://episodecalendar.com/en/shows?q[name_cont]={{PARAM}}", "5IeiE6p.png"]);
links.push(["Pirate Bay", "The Pirate Bay search for {{PARAM}}", "http://thepiratebay.org/search/{{PARAM}}/0/99/200", "cnc2XKT.png"]);
links.push(["YIFY Subtitles", "YIFY Subtitles search for {PARAM}}", "http://www.yifysubtitles.com/search?q={{PARAM}}", "VyMFcXf.png"]);
links.push(["Imgur", "Imgur search for {{PARAM}}", "http://imgur.com/search?q={{PARAM}}", "bMdIHrQ.png"]);
var titleText = $('div.title_wrapper > h1').html().split(" span.itemprop').text();
$(CreateLinkContainer(links, titleText, lgSettings['ImdbStyle'], lgSettings['ImdbNewtab'])).insertAfter('div.infobar');
$('div#name-job-categories').css({'margin-bottom':'4px'});
}else if(UrlContains("/character/")){
links.push(["YouTube", "YouTube search for {{PARAM}}", "http://www.youtube.com/results?search_query={{PARAM}}", "Oi6BUxD.png"]);
links.push(["Google Image", "Google Image search for {{PARAM}}", "http://www.google.com/search?tbm=isch&q={{PARAM}}", "FFntMod.png"]);
links.push(["Google", "Google search for {{PARAM}}", "http://www.google.com/search?output=search&q={{PARAM}}", "Ocn9d7X.png"]);
links.push(["Wikipedia", "Wikipedia search for {{PARAM}}", "http://en.wikipedia.org/w/index.php?title=Special:Search&search={{PARAM}}", "8GnE9TT.png"]);
links.push(["Rotten Tomatoes", "Rotten Tomatoes search for {{PARAM}}", "http://www.rottentomatoes.com/search/?search={{PARAM}}&sitesearch=rt", "KdEB9NR.png"]);
links.push(["MetaCritic", "MetaCritic search for {{PARAM}}", "http://www.metacritic.com/search/all/{{PARAM}}/results", "j84MuyF.png"]);
links.push(["AllMovie", "AllMovie search for {{PARAM}}", "http://www.allmovie.com/search/all/{{PARAM}}", "893QQhS.png"]);
links.push(["Box Office Mojo", "Box Office Mojo search for {{PARAM}}", "http://www.boxofficemojo.com/search/?q={{PARAM}}", "GLa3QlT.png"]);
links.push(["Imgur", "Imgur search for {{PARAM}}", "http://imgur.com/search?q={{PARAM}}", "bMdIHrQ.png"]);
var titleText = document.getElementById("tn15title").getElementsByTagName("h1")[0].innerHTML.split("")[0].trim();
$(CreateLinkContainer(links, titleText, lgSettings['ImdbStyle'], lgSettings['ImdbNewtab'])).insertBefore('div#tn15title');
$('div#lgLinkContainer').css({'float':'right'});
}
}
}
// =======================================================================================================================
// GOOGLE
if (lgSettings['GoogleEnabled'] && UrlContains('www.google.') && window.top == window.self) {
SelectiveFire(function(){
var xs = document.URL.split('?')[1];
if(xs.indexOf('#q=') != -1){
xs = xs.split('#')[1];
}
xs = xs.split('q=')[1].split('&')[0].split('#')[0];
$('a.q.qs').filter(function(index) {
return $(this).text() == 'Videos' || $(this).text() == 'Video\'s';
}).text('YouTube').attr('href', 'http://www.youtube.com/results?search_query=' + xs);
$('div._sxc > a._UXb._Jhd').filter(function(index) {
return $(this).text() == 'Videos' || $(this).text() == 'Video\'s';
}).text('YouTube').attr('href', 'http://www.youtube.com/results?search_query=' + xs);
if(lgSettings['GoogleDefinition'] && $("div.lr_dct_ent").length && !$('div#lgLinkContainer').length){
var word = $("div.lr_dct_ent > div.vk_ans > span").first().text();
links.push(["Wiktionary", "Wiktionary page on {{PARAM}}", "https://en.wiktionary.org/wiki/{{PARAM}}", "2wDa3Kq.png"]);
links.push(["Merriam-Webster", "Merriam-Webster Dictionary and Thesaurus", "http://www.merriam-webster.com/dictionary/{{PARAM}}", "3IkK6gI.png"]);
links.push(["Thesaurus.com", "Thesaurus.com", "http://thesaurus.com/browse/{{PARAM}}", "Ngxbqzc.png"]);
links.push(["Google", "Google search for define:{{PARAM}}", "http://www.google.com/search?output=search&q=define:{{PARAM}}", "Ocn9d7X.png"]);
links.push(["Synonym.com", "Synonym.com", "http://www.synonym.com/synonyms/{{PARAM}}/", "5zx9OP9.png"]);
links.push(["Wikisaurus", "Wikisaurus", "http://wiktionary.org/wiki/Wikisaurus:{{PARAM}}", "2wDa3Kq.png"]);
links.push(["One Look", "One Look", "http://www.onelook.com/?w={{PARAM}}&ls=a", "GjvfCVA.png"]);
links.push(["Wolfram|Alpha", "Wolfram|Alpha", "http://www.wolframalpha.com/input/?i={{PARAM}}", "z5p7oL7.png"]);
links.push(["Urban Dictionary", "Urban Dictionary", "http://www.urbandictionary.com/define.php?term={{PARAM}}", "oRspJNs.png"]);
links.push(["iTools", "iTools", "http://itools.com/language/dictionary?q={{PARAM}}&submit=English+Dictionary", "caWzb02.png"]);
links.push(["Vocabulary.com", "Vocabulary.com Dictionary", "http://www.vocabulary.com/dictionary/{{PARAM}}", "8MNsoze.png"]);
links.push(["Cambridge", "Cambridge Dictionary", "http://dictionary.cambridge.org/dictionary/english/{{PARAM}}", "MtWE6Yt.png"]);
links.push(["RhymeZone", "RhymeZone", "http://www.rhymezone.com/r/rhyme.cgi?Word={{PARAM}}&typeofrhyme=perfect&org1=syl&org2=l&org3=y", "d9giQh4.png"]);
links.push(["Online Etymology", "Online Etymology Dictionary", "http://www.etymonline.com/index.php?search={{PARAM}}", "uUiJWbY.png"]);
links.push(["howjsay", "howjsay: Online Dictionary of English Pronunciation", "http://howjsay.com/pronunciation-of-{{PARAM}}", "lrHhN0J.png"]);
$(CreateLinkContainer(links, word, 0, false)).insertAfter('div.lr_dct_ent > div.vk_ans');
$('div#lgLinkContainer').css({'margin-bottom':'0'});
}
}, 500);
}
// =======================================================================================================================
// End Brace for document.ready function
});