Links

Post Reply
User avatar
andrey
Posts: 1638
Joined: Sat Aug 24, 2013 3:27 pm

Links

Post by andrey » Thu Mar 16, 2017 9:59 am

Версия от 26.03.2017(11:56)

Image

Код links.html:

Code: Select all

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Links</title>
<style>

links-website div{
	padding-top: 10px;
	border-top: 1px solid rgba(153, 204, 147, 0.3);
}


links-website a{
	text-decoration: none;
	color: #0645ad;
	background: none;
}

links-website a{
	outline: 0;
}	
</style>
</head>
<body>
<links-website>
</links-website>
<script>


(function () {

var scr = document.getElementsByTagName('script');
scr = scr[scr.length - 1];
var div = scr.parentNode.parentNode.parentNode;
var artid = div.id.replace(/gdfrom-/, "");

div = div.getElementsByClassName('gddictname')[0];

if (div.className === 'gddictname')
{
	div.style.display = 'none';
}


var detect_lng = function(){

var flags = {
"it":"it",
"pl":"pl",
"de":"de",
"dk":"da",
"fr":"fr",
"en":"en",
"sn":"es",
"nl":"nl",
"pt":"pt",
"no":"no",
"cs":"cs",
"se":"sv",
"ru":"ru",
"fi":"fi",
"by":"be",
"ro":"ro",
"jp":"ja",
"cn":"zh",
"hu":"hu",
"tr":"tr",
"gr":"el"
};

	var links = document.getElementsByTagName('link');
	
	var lng;

	for (var i = 0; i < links.length; i++)
	{
		var m;
		
		if ((links[i].href) && (m = /flags\/([a-z]{2})\.png$/.exec(links[i].href)))
		{
			
			if (flags[m[1]] !== undefined)
			{
				lng = flags[m[1]];
			}
			
		}
	}

return lng;
	
}

var urlParam = function(name)
{
	
	var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);

	if (results===null)
	{
	  return undefined;
	}
	else
	{
	  return results[1] || undefined;
	}
	
}


var word = urlParam('word');
var lng = detect_lng();

if ((word) && (lng))
{

var content = '';

content += '<div><a href="https://www.google.com/search?hl=' + lng + '&lr=lang_' + lng + '&num=45' + '&q=' + word + '" target="_blank">Google</a>'; 

content += '&nbsp;<span style="color:brown">|</span>&nbsp;';

content += '<a href="https://google.com/search?hl=' + lng + '&gl=' + lng +  '&tbm=nws&q=' + word + '" target="_blank">News</a>';

content += '&nbsp;<span style="color:brown">|</span>&nbsp;';

content += '<a href="https://www.google.com/images?hl=' + lng + '&q=' + word + '" target="_blank">Images</a>';


var linguee = {
'de':'deutsch-englisch',
'nl':'nederlands-engels',
'fr':'francais-anglais',
'es':'espanol-ingles',
'pt':'portugues-ingles',
'it':'italiano-inglese',
'de':'deutsch-englisch',
'sv':'svensk-engelsk',
'da':'dansk-engelsk',
'pl':'polski-angielski',
'cs':'czech-english',
'bg':'bulgarian-english',
'el':'greek-english',
'ru':'russian-english',
'en':'english-russian',
'ro':'romanian-english',
'hu':'hungarian-english',
'fi':'finnish-english',
'zh':'chinese-english',
'ja':'japanese-english'
};


if (linguee[lng])
{

	content += '&nbsp;<span style="color:brown">|</span>&nbsp;';
	content +=  '<a href="http://www.linguee.com/' + linguee[lng] + '/search?query=' + word + '" target="_blank">Linguee</a>';
	
}

content += '</div><br>';


var span = document.getElementById("gdfrom-" + artid);
span.getElementsByTagName('links-website')[0].innerHTML = content;
//span.getElementsByClassName('gddictname')[0].style.display = 'inline';
	
}

})(); 
	

</script>

</body>
</html>
Для подключения в настройках GoldenDict-а в разделе Websites нужно добавить ссылку такого рода:

Code: Select all

file:///path/to/links.html?word=%GDWORD%
Чекбокс в колонке "As link" должен быть оставлен пустым.
Программа работает только внутри группы с флажком.
Ибо код языка берётся из имени флажка, см. код.

Иконка:
Image

Post Reply