// ==UserScript==
// @name Bunpro Toolbox
// @version 1.1.11
// @description Adds various search options from Japanese resources
// @author Ambo100
// @match *bunpro.jp/grammar_points/*
// @grant none
// @namespace https://greasyfork.org/users/230700
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var grammarPoint = document.getElementsByClassName("meaning__japanese")[0].innerText;
var toolboxDiv;
AddToolbox();
//TOOKBOX LINKS START//
//Dictionaries, References
AddLink("Jisho", "https://jisho.org/search/");
AddLink("Wikitionary", "https://en.wiktionary.org/wiki/","#Japanese");
AddLink("Eijirou", "https://eow.alc.co.jp/search?q=","");
AddDivider();
//YouTube
AddLink("YouGlish", "https://youglish.com/pronounce/","/japanese?");
AddLink("YouTube", "https://www.youtube.com/results?search_query=","+Japanese");
AddDivider();
//Q&A, Communities
AddLink("Stack Exchange", "https://japanese.stackexchange.com/search?q=","");
AddLink("WK Forum", "https://community.wanikani.com/search?q=","%20category%3A17");
AddLink("Reddit", "https://www.reddit.com/r/LearnJapanese/search?q=");
//TOOLBOX LINKS END//
FixBrokenLinks();
function AddToolbox()
{
var grammarDiv = document.getElementsByClassName("section")[0];
toolboxDiv = document.createElement("div");
grammarDiv.append(toolboxDiv);
//Toolbox styling
toolboxDiv.classList.add('related-grammar__holder');
toolboxDiv.style.marginBottom = "0px";
toolboxDiv.style.paddingBottom = "25px";
}
function AddLink(linkName, urlPrefix = '', urlSuffix = '')
{
toolboxDiv.innerHTML += '' + linkName + '';
}
function AddDivider(padding = '10')
{
toolboxDiv.innerHTML += '|';
}
function FixBrokenLinks()
{
var links = document.getElementsByTagName("a");
var regex = /^(http?:\/\/)[^.]+\.(jgram|tanos)(.+)$/i;
for (var i = 0, iMax = links.length; i < iMax; i++) {
links[i].href = links[i].href.replace(regex, "https://web.archive.org/web/" + links[i].href);
}
}
}
)();