מדיה ויקי:Common.js/externalsmaker.js – הבדלי גרסאות
אין תקציר עריכה |
חלוקת קונטרסים (שיחה | תרומות) אוצר החכמה מויקיפדיה: https://he.wikipedia.org/wiki/%D7%9E%D7%93%D7%99%D7%94_%D7%95%D7%99%D7%A7%D7%99:Common.js/externalsmaker.js |
||
| (16 גרסאות ביניים של 2 משתמשים אינן מוצגות) | |||
| שורה 1: | שורה 1: | ||
function wikiit() { | function wikiit(event, force_popup) { | ||
window.$ = window.jQuery; | |||
function dateFormat(dateArr) { | |||
if (dateArr instanceof Array) { | |||
var m = ["ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"]; | |||
if (dateArr.length != 3) | if (dateArr.length != 3) | ||
return ''; | return ''; | ||
dateArr[1] = m[Number(dateArr[1]) - 1]; | |||
if (Number(dateArr[2]) <= 50) | |||
dateArr[2] = 20 + dateArr[2]; | |||
else if (Number(dateArr[2]) >= 50 && Number(dateArr[2]) < 100) | |||
dateArr[2] = 19 + dateArr[2]; | |||
if (dateArr[0].charAt(0) == '0') | |||
dateArr[0] = dateArr[0].substring(1, dateArr[0].length); | |||
dateArr = dateArr[0] + " ב" + dateArr[1] + " " + dateArr[2]; | |||
} | } | ||
return jQuery.trim(dateArr); | return jQuery.trim(dateArr); | ||
} | } | ||
function engDateParse(engDate) | function engDateParse(engDate) { | ||
var m = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; | |||
var m = ["January" , "February" , "March" , "April", "May", "June", "July", "August", "September", "October","November", "December"]; | |||
engDate = engDate.match(/(\w+) (\d+), (\d+)/); | engDate = engDate.match(/(\w+) (\d+), (\d+)/); | ||
return [engDate[2], (m.indexOf(engDate[1]) + 1) , engDate[3] ]; | return [engDate[2], (m.indexOf(engDate[1]) + 1), engDate[3]]; | ||
} | } | ||
function match (str, expr){str = str?str.match(expr):str; return (str&&str.length>1)?str[1]:'';} | function match(str, expr) { str = str ? str.match(expr) : str; return (str && str.length > 1) ? str[1] : ''; } | ||
function getParameterByName(name) { | |||
/* http://james.padolsey.com/javascript/bujs-1-getparameterbyname/ */ | |||
var match = RegExp('[?&]' + name + '=([^&]*)') | |||
.exec(window.location.search); | |||
return match && decodeURIComponent(match[1].replace(/\+/gi, ' ')); | |||
} | |||
var VE = ' ו', | |||
TODAY = 'היום', | |||
YESTERDAY = 'אתמול'; | |||
var data = [ | var data = [ | ||
| שורה 76: | שורה 87: | ||
] | ] | ||
}, | }, | ||
{ | |||
hostname: 'old2.ih.chabad.info', hrefmatch:/#!g=1&tag=*/, | |||
params: [ | |||
{ str: 'תגית באינפו הישן' }, | |||
{ telem: 'div.news_action_desc',remove:["תגית: "] } | |||
] | |||
}, | |||
{ | { | ||
hostname: 'chabad.info', hrefmatch:/tag/, | hostname: 'chabad.info', hrefmatch:/tag/, | ||
params: [ | params: [ | ||
{ str: 'קישור לתג באינפו' }, | { str: 'קישור לתג באינפו' }, | ||
{ telem: ' | { telem: 'h2:first',remove:["Posts related to the tag '","': "] } | ||
] | ] | ||
}, | }, | ||
{ | |||
hostname: 'chabad.info', hrefmatch:/(.*)\/(.*)/, | |||
params: [ | |||
{ str: 'קישור חבד אינפו' }, | |||
{ telem: 'div.banner_category' }, | |||
{ str: location.pathname.split('/')[2]}, | |||
{ telem: '.div-post-ttl > h1:nth-child(1)'} , | |||
{ telem: '.single-author > div:nth-child(1)' }, | |||
{ telem: '.single-author > div:nth-child(2)' } | |||
] | |||
}, | |||
{ | { | ||
hostname: 'old2.ih.chabad.info', | hostname: 'old2.ih.chabad.info',hrefmatch:/#!g=1&url=article*/, | ||
params: [ | params: [ | ||
{ str: 'קישור חבד אינפו' }, | { str: 'קישור חבד אינפו ישן' }, | ||
{ urlparam: 'id' }, | { urlparam: 'id' }, | ||
{ telem: 'div.art_title' }, | { telem: 'div.art_title' }, | ||
{ telem: 'div.art_author' }, | { telem: 'div.art_author' }, | ||
{ telem: 'div.art_time_id', match:/(\d+\.\d+\.\d+)/, split:'.', func:dateFormat} | { telem: 'div.art_time_id', match:/(\d+\.\d+\.\d+)/, split:'.', func:dateFormat } | ||
] | ] | ||
}, | }, | ||
| שורה 111: | שורה 142: | ||
params: [ | params: [ | ||
{ str: 'קישור הגאולה' }, | { str: 'קישור הגאולה' }, | ||
{ str: location.href, match: /hageula.com\/[^/]+\/([^/]+)\/\d+\. | { str: location.href, match: /hageula.com\/[^/]+\/([^/]+)\/\d+\.htm/ }, | ||
{ str: location.href, match: /hageula.com\/[^/]+\/[^/]+\/(\d+)\. | { str: location.href, match: /hageula.com\/[^/]+\/[^/]+\/(\d+)\.htm/ }, | ||
{ telem: 'h1:first' }, | { telem: 'h1:first' }, | ||
{ elem: ['a[href^="/author"]', 'parent', 'text'], remove:"מערכת האתר"}, | { elem: ['a[href^="/author"]', 'parent', 'text'], remove:"מערכת האתר"}, | ||
{ telem: 'table.Aborder tr:first td:last div', split:'.', func:dateFormat}, | { telem: 'table.Aborder tr:first td:last div', split:'.', func:dateFormat}, | ||
{ str: location.href, match: /hageula.com\/([^/]+)\/[^/]+\/\d+\. | { str: location.href, match: /hageula.com\/([^/]+)\/[^/]+\/\d+\.htm/, defvalue:'news'} | ||
] | ] | ||
}, | }, | ||
| שורה 164: | שורה 195: | ||
{ func: function(){return prompt("שם כתב")}} | { func: function(){return prompt("שם כתב")}} | ||
] | ] | ||
}, | |||
{ | |||
hostname: 'otzar.org', | |||
params: [ | |||
{ str: 'אוצר החכמה' }, | |||
[ | |||
{ urlparam: 'book', func: function(bookid){ | |||
if (!bookid) try{bookid = $('#book-iframe').attr('src').match(/book=(\d+)/)[1]}catch{} | |||
if (bookid && location.hostname == 'tablet.otzar.org') { | |||
window.detail_data = | |||
JSON.parse($.post({url:'//tablet.otzar.org/he/php/detailBook.php', async: false, | |||
data:'{"ParamQuery":"{\\"NUMBOOK\\":\\"'+bookid+'\\",\\"USERDATAID\\":0}","sqlFile":"selectSubOfBook"}'} | |||
).responseText).arr[0]; | |||
} else if (window.booknameS && window.authorS){ | |||
bookid = bookid || window.bookid; | |||
window.detail_data = { | |||
AUTHOR: authorS, | |||
FULLNAME: booknameS, | |||
bookid: bookid, | |||
} | |||
} else { | |||
bookid = bookid || window.bookid; | |||
var parts = $('title').text().replace(' - אוצר החכמה','').split('/'); | |||
window.detail_data = { | |||
AUTHOR: parts[1], | |||
FULLNAME: parts[0], | |||
YEAR: parts[2], | |||
PrintedP_AND_YEAR: parts[0].split('-')[1], | |||
bookid: bookid, | |||
} | |||
} | |||
}}, // TODO: hack to have all the info ready in tablet page | |||
{ var: ['detail_data', 'AUTHOR']}, | |||
], | |||
{ var: ['detail_data','FULLNAME']}, | |||
{ var: ['detail_data','bookid']}, | |||
[ | |||
{ var: ['detail_data', 'PrintedP_AND_YEAR']}, | |||
{ func: function () { | |||
return [ | |||
window.detail_data['PrintedP'].match(/[\u0590-\u05FF ]+/)[0], | |||
window.detail_data['YEAR'], | |||
].join(' ') | |||
}}, | |||
{ var: ['detail_data', 'YEAR']}, | |||
], | |||
{ str: '' }, | |||
[ | |||
{ attr: ["ab", "value"], match: /^([^ ]*) /, prefix: 'עמוד=' }, | |||
{ elem: ["#ab", "val"], prefix: 'עמוד=', match: /^(\d+) / }, | |||
{ urlparam: 'pagenum', prefix: 'עמוד=' } | |||
], | |||
] | |||
}, | }, | ||
{ | { | ||
| שורה 215: | שורה 299: | ||
{func:function(_){return prompt("האדמו\"ר מחבר הספר?");}}, | {func:function(_){return prompt("האדמו\"ר מחבר הספר?");}}, | ||
] | ] | ||
} | } | ||
]; | ]; | ||
for (var i = 0; i < data.length; i++) { | |||
if ( | |||
location.hostname.match(data[i].hostname) | |||
&& (!data[i].hrefmatch || location.href.match(data[i].hrefmatch)) | |||
&& (!data[i].condition || data[i].condition()) | |||
) { | |||
var params = []; | |||
for (var j = 0; j < data[i].params.length; j++) { | |||
if (!(data[i].params[j] instanceof Array)) { | |||
data[i].params[j] = [data[i].params[j]]; | |||
} | } | ||
if (typeof(params[j]) != "string") | for (var k=0; k < data[i].params[j].length; k++) { | ||
try { | |||
var curParam = data[i].params[j][k]; | |||
params[j] = ''; | |||
if (typeof curParam.str != "undefined") { | |||
params[j] = curParam.str; | |||
} else if (typeof curParam.ldjson != "undefined") { | |||
var ldjson = null | |||
var ldjsons = $('script[type="application/ld+json"]').map(function(i,e){return JSON.parse($(e).text())}) | |||
if (typeof curParam.ldjson.n != "undefined"){ | |||
ldjson = ldjsons[curParam.ldjson.n] | |||
} else { | |||
var filteredLdjson = ldjsons.filter(function(i,e){return (curParam.ldjson.type?[curParam.ldjson.type]:['NewsArticle','Article']).includes(e['@type'])}) | |||
if (filteredLdjson.length == 1){ | |||
ldjson = filteredLdjson[0] | |||
} else { | |||
console.error("more/less than single ldjson", filteredLdjson) | |||
return | |||
} | |||
} | |||
if (curParam.ldjson.key == "datePublished"){ | |||
params[j] = ldjson.datePublished; | |||
if (!curParam.date){ | |||
curParam.date = ['-', '210'] | |||
} | |||
} else if (curParam.ldjson.key == "author"){ | |||
params[j] = | |||
$.map($(ldjson.author), function(a){return a.name}) | |||
.join(VE) | |||
} else if (typeof curParam.ldjson.raw != "undefined"){ | |||
if (!(curParam.ldjson.raw instanceof Array)) { | |||
curParam.ldjson.raw = [curParam.ldjson.raw] | |||
} | |||
params[j] = ldjson | |||
for (var t=0; t < curParam.ldjson.raw.length; t++){ | |||
console.log('curParam.ldjson.raw[t]', curParam.ldjson.raw[t]) | |||
params[j] = params[j][curParam.ldjson.raw[t]]; | |||
} | |||
} | |||
} else if (typeof curParam.url != "undefined") { | |||
params[j] = location.href; | |||
if (curParam.url == 'decodeURIComponent') | |||
params[j] = decodeURIComponent(params[j]) | |||
else if (curParam.url == 'decodeURI') | |||
params[j] = decodeURI(params[j]) | |||
} else if (typeof curParam.attr != "undefined"){ | |||
params[j] = jQuery('html').find(curParam.attr[0]).attr(curParam.attr[1]); | |||
} else if (typeof curParam.var != "undefined") { | |||
if (!(curParam.var instanceof Array)) | |||
curParam.var = [curParam.var] | |||
params[j] = window; | |||
for (var vi=0; vi < curParam.var.length; vi++) { | |||
params[j] = params[j][curParam.var[vi]] | |||
// console.log(vi, params[j], curParam.var[vi]) | |||
if (!params[j]) | |||
break | |||
} | |||
if (params[j] == window) | |||
params[j] = undefined | |||
} | |||
else if (typeof curParam.urlparam != "undefined") { | |||
params[j] = getParameterByName(curParam.urlparam) || ""; | |||
} else if (typeof curParam.elem != "undefined") { | |||
if (curParam.elem instanceof Array) { | |||
params[j] = jQuery('html').find(curParam.elem[0]); | |||
for (var elemIdx = 1; elemIdx < curParam.elem.length; elemIdx++) { | |||
var func = curParam.elem[elemIdx].split(','); | |||
params[j] = (func.length > 1) ? params[j][func[0]](func[1]) : params[j] = params[j][func[0]](); | |||
} | |||
if (typeof (params[j]) != "string") | |||
params[j] = params[j].html(); | |||
} | |||
else | |||
params[j] = jQuery('html').find(curParam.elem).html(); | |||
} | |||
else if (typeof curParam.first_text_node != "undefined"){ | |||
params[j] = jQuery('html').find(curParam.first_text_node).contents().filter(function () { return this.nodeType === 3 }).text() | |||
} else if (typeof curParam.elements != "undefined" || (typeof curParam.telements != "undefined")) { | |||
var sep; | |||
if (typeof curParam.elements != "undefined"){ | |||
params[j] = jQuery('html').find(curParam.elements[0]).map(function (el) { return $(this).html(); }).toArray() | |||
sep = curParam.elements[1]; | |||
} | |||
if (typeof curParam.telements != "undefined"){ | |||
params[j] = jQuery('html').find(curParam.telements[0]).map(function (el) { return $(this).text(); }).toArray(); | |||
sep = curParam.telements[1]; | |||
} | |||
if (sep != VE){ // hack for VE | |||
params[j] = params[j].join(sep); | |||
} else { | |||
if (params[j].length > 2){ | |||
params[j] = [params[j].slice(0,-1).join(', '), params[j].slice(-1)].join(sep); | |||
} else { | |||
params[j] = params[j].join(sep); | |||
} | |||
} | |||
} | |||
else if (typeof curParam.telem != "undefined") { | |||
params[j] = jQuery('html').find(curParam.telem).first().text().trim(); | |||
} | |||
if (typeof curParam.match != "undefined") { | |||
if (!(curParam.match instanceof Array)) | |||
params[j] = match(params[j], curParam.match); | |||
else for (var patIdx = 0; patIdx < curParam.match.length; patIdx++) { | |||
var temp = match(params[j], curParam.match[patIdx]); | |||
if (temp != '') { | |||
params[j] = temp; | |||
break; | |||
} | |||
} | |||
} | |||
if (typeof curParam.remove != "undefined") | |||
for (var removeIdx = 0; removeIdx < curParam.remove.length; removeIdx++) | |||
params[j] = params[j].replace(curParam.remove[removeIdx], ""); | |||
if (typeof curParam.split != "undefined") | |||
params[j] = params[j].split(curParam.split); | |||
if (typeof curParam.func != "undefined") { | |||
if (!(curParam.func instanceof Array)) | |||
curParam.func = [curParam.func]; | |||
for (var funcIdx = 0; funcIdx < curParam.func.length; funcIdx++) { | |||
params[j] = curParam.func[funcIdx](params[j]); | |||
} | |||
} | |||
if (typeof curParam.date != "undefined") { | |||
if (!(curParam.date instanceof Array)) | |||
curParam.date = [curParam.date, [0,1,2]]; | |||
var sep = curParam.date[0].replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | |||
params[j] = match(params[j], RegExp(('(\\d+' + sep + '\\d+' + sep + '\\d+)'))) | |||
if (params[j]){ | |||
params[j] = params[j].split(curParam.date[0]); | |||
params[j] = [params[j][curParam.date[1][0]], params[j][curParam.date[1][1]], params[j][curParam.date[1][2]]] | |||
params[j] = dateFormat(params[j]); | |||
} | |||
} | |||
if (typeof curParam.stringDate != "undefined") { | |||
if (params[j]) { | |||
var today = new Date(), | |||
dd = (today.getDate() - (params[j] == YESTERDAY ? 1 : 0)).toString(), | |||
mm = (today.getMonth() + 1).toString(), | |||
yy = today.getFullYear().toString().slice(-2); | |||
params[j] = dateFormat([dd, mm, yy]); | |||
} | |||
} | |||
if (typeof params[j] == "string") { | |||
try { | |||
params[j] = jQuery.trim(decodeURIComponent(params[j])) | |||
} catch (e) { | |||
console.error(e) | |||
} | |||
params[j] = params[j] | |||
.replace(/ |\u202B-\u202d/gm, " " | |||
.replace(/\s+/gm, ' ')) | |||
.replace(/=/g, "{{=}}") | |||
.replace(/(\|\|?)/gm, function(x) { return "{{" + x.replace(/\|/g, "!") + "}}" }) | |||
.replace(/(\|\|?)/gm, function(x) { return "{{" + x.replace(/\|/g, "!") + "}}" }); | |||
} | |||
else if (jQuery.isArray(params[j])) { | |||
params[j] = jQuery.trim(params[j].join("|")); | |||
} | |||
if (params[j] && typeof curParam.prefix != "undefined") | |||
params[j] = curParam.prefix + params[j]; | |||
if (typeof curParam.defvalue != "undefined" && params[j] == curParam.defvalue) | |||
params[j] = ''; | |||
if (typeof curParam.shouldnt != "undefined" && typeof params[j] == "string" && params[j].match(curParam.shouldnt)) | |||
params[j] = ''; | |||
if ((params[j] != '') && (params[j] != undefined)) { | |||
console.log('found', j, params[j]) | |||
break; | |||
} | |||
console.log('not found', j, curParam) | |||
} | |||
catch (e) { | |||
console.error(e) | |||
} | |||
} | |||
} | |||
var minimum = (typeof data[i].minimum != "undefined") ? (data[i].minimum) : (0); | |||
while (params[params.length - 1] == "" && params.length > minimum) //remove all last empty params | |||
params | params.pop(); | ||
if (window.popup_template_canceled && !force_popup){ | |||
console.log('popup_template_canceled'); | |||
} else { | |||
var result = '{{' + params.join('|') + '}}' | |||
if (prompt("לחיצה על אישור תעתיק את התבנית:", result) != null){ | |||
$('<input>').val(result).appendTo('body').select();document.execCommand('copy'); | |||
} | |||
window.popup_template_canceled = false; | |||
if (window.old$) {window.$ = window.old$;} | |||
} | |||
return | |||
} | |||
} | |||
try { | |||
var ldjson = $('script[type="application/ld+json"]').map(function(i,e){return JSON.parse($(e).text())}).filter(function(i,e){return ['NewsArticle', 'Article', 'article'].includes(e['@type'])}) | |||
var ldjson_website = [{}] | |||
//saw on 0404 and hwzone | |||
if (ldjson.length == 0){ | |||
ldjson = $('script[type="application/ld+json"]').map(function(i,e){return JSON.parse($(e).text())}).filter(function(i,e){return e['@graph']}) | |||
if (ldjson.length == 1){ | |||
ldjson_website = ldjson[0]['@graph'].filter(function(i,e){return ['WebSite'].includes(i['@type'])}) | |||
ldjson = ldjson[0]['@graph'].filter(function(i,e){return ['WebPage'].includes(i['@type'])}) | |||
} | } | ||
} | |||
k = | console.log('ldjson:', ldjson) | ||
if (ldjson.length == 1){ | |||
ldjson = ldjson[0] | |||
var date = new Date(ldjson.datePublished) | |||
if (isNaN(date)){ | |||
// for example in Israel Hayom | |||
date = new Date(ldjson.publisher.datePublished) | |||
} | |||
console.log('date', date) | |||
var general = { | |||
'הכותב': $.map($(ldjson.author), function(a){return a.name}).join(VE), | |||
'כותרת': ldjson.name || ldjson.headline, | |||
'אתר': (ldjson.publisher||ldjson_website[0]).name, | |||
'תאריך': dateFormat([''+date.getDay(), ''+date.getMonth(), ''+date.getFullYear()]), | |||
'כתובת': location.href | |||
} | |||
var result = '{{קישור כללי|'+$.map(general, function(v,k){ | |||
return k + '=' + jQuery.trim(decodeURIComponent($('<a />').html(v).text())).replace(/ |\u202B-\u202d/gm, " " | |||
.replace(/\s+/gm, ' ')) | |||
.replace(/=/g, "{{=}}") | |||
.replace(/''/g, '"') | |||
.replace(/(\|\|?)/gm, function (x) { return "{{" + x.replace(/\|/g, "!") + "}}" }) | |||
.replace(/(\|\|?)/gm, function (x) { return "{{" + x.replace(/\|/g, "!") + "}}" }) | |||
}).join('|') + '}}' | |||
if (prompt("לחיצה על אישור תעתיק את התבנית:", result) != null){ | |||
$('<input>').val(result).appendTo('body').select();document.execCommand('copy'); | |||
} | |||
if (window.old$) {window.$ = window.old$;} | |||
return | |||
} | } | ||
} catch (e){ | |||
console.error('failed to create general link', e) | |||
} | } | ||
alert("אתר או עמוד זה אינו נתמך על ידי הבוקמרקלט."); | |||
if (window.old$) {window.$ = window.old$;} | |||
} | } | ||
(function () | (function () { | ||
{ | if (typeof (jQuery) == "undefined"){ | ||
if (typeof(jQuery)!="undefined") | if (typeof ($) != "undefined"){ | ||
window.old$ = window.$; | |||
console.log('store old dollar') | |||
} | |||
var s = document.createElement('script'); | |||
s.setAttribute('src', "https://he.wikipedia.org/w/load.php?modules=jquery&only=scripts"); | |||
s.onload = wikiit; | |||
} | document.getElementsByTagName('body')[0].appendChild(s); | ||
} else { | |||
wikiit() | |||
} | } | ||
})(); | })(); | ||