Bing News
Posted: Wed Mar 22, 2017 6:18 am
Версия от 26.03.2017(11:43)
Ссылка на ресурс:
http://www.bing.com/news
Код bingnews.html:
Для подключения в настройках GoldenDict-а в разделе Websites нужно добавить ссылку такого рода:
Чекбокс в колонке "As link" должен быть оставлен пустым.
Программа работает только внутри группы с флажком.
Ибо код языка берётся из имени флажка, см. код.
Иконка:
Ссылка на ресурс:
http://www.bing.com/news
Код bingnews.html:
Code: Select all
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
<style>
bingnews .bnews{
border-collapse: collapse;
margin: 8px 0px 8px 0px;
}
bingnews .bnews td{
padding: 0px;
vertical-align: top;
}
bingnews .bnews td strong strong {color: #c24641;}
bingnews a.bingexternal {
background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAVElEQVR42n3PgQkAIAhEUXdqJ3dqJ3e6IoTPUSQcgj4EQ5IlUiLE0Jil3PECXhcHGBhZ8kg4hwxAu3MZeCGeyFnAXp4hqNQPnt7QL0nADpD6wHccLvnAKksq8iiaAAAAAElFTkSuQmCC);
background-image:-webkit-linear-gradient(transparent,transparent),url(data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%20standalone%3D%22no%22%3F%3E%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%2210%22%3E%3Cdefs%3E%3Cmarker%20orient%3D%22auto%22%20overflow%3D%22visible%22%3E%3Cpath%20d%3D%22M-.958-4.259c-1.134%200-2.056.922-2.056%202.056%200%20.394.143.736.336%201.049l-.07.056c-.373-.513-.954-.867-1.636-.867-1.134%200-2.056.922-2.056%202.056s.922%202.056%202.056%202.056c.596%200%201.121-.265%201.496-.671-.075.213-.126.433-.126.671%200%201.134.922%202.056%202.056%202.056s2.056-.922%202.056-2.056c0-.476-.189-.896-.462-1.245.813.158%201.627.477%202.224%201.399-.443-.443-.727-1.248-.727-2.336l-.378-.028.35-.014c0-1.087.27-1.893.713-2.336-.575.889-1.354%201.216-2.14%201.385.243-.337.42-.728.42-1.175%200-1.134-.922-2.056-2.056-2.056z%22%20fill-rule%3D%22evenodd%22%20stroke%3D%22%23000%22%20stroke-width%3D%22NaN%22%2F%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20overflow%3D%22visible%22%3E%3Cpath%20d%3D%22M0-2.828l-2.828%202.828%202.828%202.828%202.828-2.828-2.828-2.828z%22%20fill-rule%3D%22evenodd%22%20stroke%3D%22%23000%22%20stroke-width%3D%22NaN%22%2F%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20overflow%3D%22visible%22%3E%3Cpath%20d%3D%22M10%200l4-4-14%204%2014%204-4-4z%22%20fill-rule%3D%22evenodd%22%20stroke%3D%22%23000%22%20stroke-width%3D%22NaN%22%2F%3E%3C%2Fmarker%3E%3C%2Fdefs%3E%3Cpath%20fill%3D%22%23fff%22%20stroke%3D%22%2306c%22%20d%3D%22M.5%203.518h5.982v5.982h-5.982z%22%2F%3E%3Cpath%20d%3D%22M4.755-.16h5.234v5.39l-1.571%201.544-1.31-1.31-2.725%202.725-2.688-2.688%202.808-2.808-1.31-1.31z%22%20fill%3D%22%2306f%22%2F%3E%3Cpath%20d%3D%22M8.984.845l.022%204.884-1.817-1.817-2.881%202.881-1.227-1.227%202.881-2.881-1.85-1.851z%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fsvg%3E);
background-image:linear-gradient(transparent,transparent),url(data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%20standalone%3D%22no%22%3F%3E%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%2210%22%3E%3Cdefs%3E%3Cmarker%20orient%3D%22auto%22%20overflow%3D%22visible%22%3E%3Cpath%20d%3D%22M-.958-4.259c-1.134%200-2.056.922-2.056%202.056%200%20.394.143.736.336%201.049l-.07.056c-.373-.513-.954-.867-1.636-.867-1.134%200-2.056.922-2.056%202.056s.922%202.056%202.056%202.056c.596%200%201.121-.265%201.496-.671-.075.213-.126.433-.126.671%200%201.134.922%202.056%202.056%202.056s2.056-.922%202.056-2.056c0-.476-.189-.896-.462-1.245.813.158%201.627.477%202.224%201.399-.443-.443-.727-1.248-.727-2.336l-.378-.028.35-.014c0-1.087.27-1.893.713-2.336-.575.889-1.354%201.216-2.14%201.385.243-.337.42-.728.42-1.175%200-1.134-.922-2.056-2.056-2.056z%22%20fill-rule%3D%22evenodd%22%20stroke%3D%22%23000%22%20stroke-width%3D%22NaN%22%2F%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20overflow%3D%22visible%22%3E%3Cpath%20d%3D%22M0-2.828l-2.828%202.828%202.828%202.828%202.828-2.828-2.828-2.828z%22%20fill-rule%3D%22evenodd%22%20stroke%3D%22%23000%22%20stroke-width%3D%22NaN%22%2F%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20overflow%3D%22visible%22%3E%3Cpath%20d%3D%22M10%200l4-4-14%204%2014%204-4-4z%22%20fill-rule%3D%22evenodd%22%20stroke%3D%22%23000%22%20stroke-width%3D%22NaN%22%2F%3E%3C%2Fmarker%3E%3C%2Fdefs%3E%3Cpath%20fill%3D%22%23fff%22%20stroke%3D%22%2306c%22%20d%3D%22M.5%203.518h5.982v5.982h-5.982z%22%2F%3E%3Cpath%20d%3D%22M4.755-.16h5.234v5.39l-1.571%201.544-1.31-1.31-2.725%202.725-2.688-2.688%202.808-2.808-1.31-1.31z%22%20fill%3D%22%2306f%22%2F%3E%3Cpath%20d%3D%22M8.984.845l.022%204.884-1.817-1.817-2.881%202.881-1.227-1.227%202.881-2.881-1.85-1.851z%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fsvg%3E);
background-repeat:no-repeat;
background-position:center right;
padding-right:13px
}
bingnews .bnews img {
background: #FFFFFF;
border: 1px solid #D5D5D5;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.102);
padding: 2px;
}
bingnews .bnewsmatch {
color: #c24641;
}
bingnews .bnews strong{
color: #34282c;
}
</style>
<title>Bing News</title>
</head>
<body>
<script type="text/javascript">
(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 urlParam = function (name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results===null)
{
return undefined;
}
else
{
return results[1] || undefined;
}
}
var getbingnews = function (artid, lng)
{
var word = urlParam('word');
if ((word) && (word.trim().length > 4))
{
var url = 'http://www.bing.com/news?mkt=' + lng + '&q=' + word;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
try
{
var s = '';
var body = /<body.*>([\s\S]+)<\/body>/.exec(xhttp.responseText);
body = $.parseHTML(body[1]);
body = $('<output>').append(body);
body.find('div.newsitem').each(function(i, elem) {
var u = $(this).find('a.title').attr('href');
var h = $(this).find('a.title').html();
var t = $(this).find('div.snippet').html();
var src = $(this).find('div.source').find('a').text();
var time = $(this).find('span.timestamp').text();
var img = $(this).find('img.rms_img').attr('src');
var img = $(this).find('img.rms_img').attr('id');
if (img)
{
img = body.find("#" + img + "DIV").text();
}
if ((u) && (h) && (t) && (src) && (time) && (img))
{
s += "\n" + '<table border=0 class=bnews><tr>';
s += "<td rowspan=2><img src=\"" + img + "\" /></td>";
s += "<td style='padding: 4px 0px 0px 4px'><strong>";
h = h.replace(/<strong>/ig, '<span class=bnewsmatch>');
h = h.replace(/<\/strong>/ig, '</span>');
s += h;
t = t.replace(/<strong>/ig, '<span class=bnewsmatch>');
t = t.replace(/<\/strong>/ig, '</span>');
s += "</strong><div style='margin-top:4px;'>" + t + '</div></td>';
u = "<a target=_blank class=bingexternal href='" + u + "'></a>";
u = "<div style='color:#999;margin:4px 0px 0px 4px'>" + "<span>" + src + "</span> <span>(" + time + ")</span> " + u + "</div>";
s += '</tr><tr><td>' + u + '</td></tr></table>';
}
});
if (s !== '')
{
var span = document.getElementById("gdfrom-" + artid);
span.getElementsByTagName('bingnews')[0].innerHTML = s;
span.getElementsByClassName('gddictname')[0].style.display = 'block';
}
}
catch(e)
{
return false;
}
};
}
xhttp.open("GET", url, true);
xhttp.send();
}
}
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 bing_lng = {
'bg':'bg-BG',
'cs':'cs-CZ',
'da':'da-DK',
'de':'de-DE',
'en':'en-US',
'es':'es-ES',
'fr':'fr-FR',
'it':'it-IT',
'nl':'nl-NL',
'no':'nb-NO',
'pl':'pl-PL',
'pt':'pt-BR',
'ru':'ru-ru',
'sv':'sv-SE'
};
var lng = detect_lng();
if ((lng) && (bing_lng[lng]))
{
getbingnews(artid, bing_lng[lng]);
}
})();
</script>
<bingnews></bingnews>
</body>
</html>
Code: Select all
file:///path/to/bingnews.html?word=%GDWORD%
Программа работает только внутри группы с флажком.
Ибо код языка берётся из имени флажка, см. код.
Иконка: