מדיה ויקי:Common.js/externalsmaker.js: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
(תאריכים עבריים עם גרש) |
(הוספת המרה לתאריך עברי (בעזרת תבנית:תע) בהתאם למקובל באתר) |
||
שורה 3: | שורה 3: | ||
function dateFormat(dateArr) | function dateFormat(dateArr) | ||
{ | { | ||
if (dateArr instanceof Array) | if (dateArr instanceof Array) | ||
{ | { | ||
if (dateArr.length != 3) | if (dateArr.length != 3) | ||
return ''; | return ''; | ||
m = dateArr[1]; d = dateArr[0]; y = dateArr[2] | |||
return "{{תע+|+"+m+"/"+d+"/"+y+"}}"; | |||
} | } | ||
return jQuery.trim(dateArr); | return jQuery.trim(dateArr); | ||
שורה 60: | שורה 20: | ||
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]:'';} | ||
שורה 102: | שורה 60: | ||
{ str: location.href, match: /hageula.com\/news\/[^/]+\/(\d+).html/ }, | { str: location.href, match: /hageula.com\/news\/[^/]+\/(\d+).html/ }, | ||
{ telem: 'h1:first' }, | { telem: 'h1:first' }, | ||
{ elem: ['a[href^="/author"]', 'parent', 'text']}, | { 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} | ||
] | ] | ||
שורה 282: | שורה 240: | ||
.replace("=","{{=}}") | .replace("=","{{=}}") | ||
.replace(/''/g,'"') | .replace(/''/g,'"') | ||
.replace(/(\|\|?)/gm,function(x){return "{{" + x.replace(/\|/g,"!") + "}}";})); | .replace(/(\|\|?)/gm,function(x){return "{{" + x.replace(/\|/g,"!") + "}}";}) | ||
.replace("+{{!}}+","|") | |||
); | |||
} | } | ||
else if (jQuery.isArray(params[j])) | else if (jQuery.isArray(params[j])) |
גרסה מ־23:39, 12 באוגוסט 2014
function wikiit() {
function dateFormat(dateArr)
{
if (dateArr instanceof Array)
{
if (dateArr.length != 3)
return '';
m = dateArr[1]; d = dateArr[0]; y = dateArr[2]
return "{{תע+|+"+m+"/"+d+"/"+y+"}}";
}
return jQuery.trim(dateArr);
}
function engDateParse(engDate)
{
var m = ["January" , "February" , "March" , "April", "May", "June", "July", "August", "September", "October","November", "December"];
engDate = engDate.match(/(\w+) (\d+), (\d+)/);
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 getParameterByName(name)
{
/* http://james.padolsey.com/javascript/bujs-1-getparameterbyname/ */
var match = RegExp('[?&]' + name + '=([^&]*)')
.exec(window.location.href);
return match && decodeURIComponent(match[1].replace(/\+/gi, ' '));
}
var data = [
{
hostname: 'www.chabad.info',
params: [
{ str: 'קישור חבד אינפו' },
{ urlparam: 'id' },
{ telem: 'div.art_title' },
{ telem: 'div.art_author' },
{ telem: 'div.art_time_id', match:/(\d+\.\d+\.\d+)/, split:'.', func:dateFormat}
]
},
{
hostname: 'www.chabad.co.il',
params: [
{ str: 'קישור חבד בישראל' },
{ urlparam: 'topic' },
{ urlparam: 'article' },
{ telem: 'div.art_title' },
{ telem: 'div.art_author' },
{ telem: 'div.art_date', match:/(\d+\.\d+\.\d+)/, split:'.', func:dateFormat }
]
},
{
hostname: 'hageula.com',
params: [
{ str: 'קישור הגאולה' },
{ str: location.href, match: /hageula.com\/news\/([^/]+)\/\d+.html/ },
{ str: location.href, match: /hageula.com\/news\/[^/]+\/(\d+).html/ },
{ telem: 'h1:first' },
{ elem: ['a[href^="/author"]', 'parent', 'text'], remove:"מערכת האתר"},
{ telem: 'table.Aborder tr:first td:last div', split:'.', func:dateFormat}
]
},
{
hostname: 'col.org.il',
params: [
{ str: 'קישור חבד און ליין' },
[
{ urlparam: 'artID'},
{ str:location.href, match:/_(\d+)\.html?$/}
],
{ telem: 'table:eq(6) div:first' },
{ str: '' }, //author
{ telem: 'table:eq(6) div:eq(1)', match:/\(יום .+, (.*?)\)/}
]
},
{
hostname: 'www.shturem.net',
params: [
{ str: 'קישור שטורעם' },
{ urlparam:'section', defvalue:'news' },
{ urlparam:'id' },
{ telem: '.artTitle' },
{ telem: '.artReporter' },
{ telem: '.artDate' }
]
},
{
hostname: 'www.chabad.org.il', hrefmatch:/Magazines/,
params: [
{ str: 'קישור התקשרות צאח' },
{ urlparam: 'CategoryID' },
{ urlparam: 'ArticleID' },
{ telem: "a.navigationTab:contains('התקשרות'):last" , match:/(\d+)/ },
{ telem: ".CategoryTitle" },
{ telem: '.bodyinsmall' , match:/^מאת:?(.*?)\n/m },
]
},
{
hostname: "www.scribd.com",
params: [
{ str: 'קישור בית משיח'},
{ str: location.href, match: /doc\/(\d+)\//},
{ func: function(){return $(".pager input").val();} },
{ telem: "h1.book_title"},
{ func: function(){return prompt("כותרת כתבה")}},
{ func: function(){return prompt("שם כתב")}}
]
},
{
hostname: /otzar770.com/,
params: [
{ str: 'קישור אוצר 770' },
[
{ urlparam:"nBookId"},
{ str:'', func: function(_){return $($($("frame[name='site']")[0].contentWindow.document)
.find("frame[name='main']")[0].contentWindow.document)
.find("iframe#mainArea").contents().get(0).location.href.match(/nBookId=(\d+)/)[1]}
}
],
[
{ urlparam:"nPageNumber"},
{ str:'', func: function(_){return $($($($("frame[name='site']")[0].contentWindow.document)
.find("frame[name='main']")[0].contentWindow.document)
.find("iframe#mainArea").contents()
.find("frame[name='navFrame']")[0]
.contentWindow.document).find("input[name=nCurrentPage]").val()}}
],
[
{ urlparam:"cPartLetter"},
{ str:'', func: function(_){return $($($($("frame[name='site']")[0].contentWindow.document)
.find("frame[name='main']")[0].contentWindow.document)
.find("iframe#mainArea").contents()
.find("frame[name='navFrame']")[0]
.contentWindow.document).find("input[name=cPartLetter]").val()}}
],
{str:'', func: function(_){
var main = $("frame[name='site']").length ?
$($($("frame[name='site']")[0].contentWindow.document).find("frame[name='main']")[0].contentWindow.document):
document;
var title = $($(main)
.find("iframe#mainArea").contents()
.find("frame[name='navFrame']")[0]
.contentWindow.document).find("#titleSpan").text();
rm = ["(מוגה)","(בלתי מוגה)", /^מאמרים/g, "ספרים שונים", "(Edited)","(Unedited)", 'ספרים בלה"ק'];
for (x in rm) title = title.trim().replace(rm[x],'');
return title},
},
{func:function(_){return prompt("האדמו\"ר מחבר הספר?");}}
]
},
];
var isFound = false;
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 = [];
var k = 0;
for (var j = 0; j < data[i].params.length; j++)
try {
var curParam = (data[i].params[j] instanceof Array)?(data[i].params[j][k]):(data[i].params[j]);
params[j] = '';
if (typeof curParam.str != "undefined")
params[j] = curParam.str;
else if (typeof curParam.urlparam!= "undefined")
params[j] = getParameterByName(curParam.urlparam)||"";
else if (typeof curParam.elem != "undefined")
{
if (curParam.elem instanceof Array)
{
params[j] = $(curParam.elem[0]);
for(var elemIdx = 1; elemIdx < curParam.elem.length; elemIdx++)
{
var func = curParam.elem[elemIdx].split(',');
params[j] = params[j][func[0]](func.length>0?func[1]:null);
}
if (typeof(params[j]) != "string")
params[j] = params[j].html();
}
else
params[j] = $(curParam.elem).html();
}
else if (typeof curParam.elements != "undefined")
{
params[j] = $(curParam.elements[0]).map(function(el){return $(this).html();}).toArray().join(curParam.elements[1]);
}
else if (typeof curParam.telements != "undefined")
{
params[j] = $(curParam.telements[0]).map(function(el){return $(this).text();}).toArray().join(curParam.telements[1]);
}
else if (typeof curParam.telem != "undefined")
{
params[j] = $(curParam.telem).first().text();
}
if (typeof curParam.match != "undefined")
{
if (!(curParam.match instanceof Array))
params[j] = match(params[j], curParam.match);
else for (patIdx = 0; patIdx < curParam.match.length; patIdx++)
{
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 params[j] == "string")
{
params[j] = jQuery.trim(unescape(params[j].replace(/ |\u202B|\u202C/gm," ").replace(/\s+/gm, ' '))
.replace("=","{{=}}")
.replace(/''/g,'"')
.replace(/(\|\|?)/gm,function(x){return "{{" + x.replace(/\|/g,"!") + "}}";})
.replace("+{{!}}+","|")
);
}
else if (jQuery.isArray(params[j]))
{
params[j] = jQuery.trim(params[j].join("|"));
}
if (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] == '') && (data[i].params[j] instanceof Array) && (k < data[i].params[j].length - 1))
{
k++;
j--;
continue;
}
k = 0;
}
catch(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.pop();
prompt("Your template:", '{{' + params.join('|') + '}}');
isFound = true;
break;
}
}
if (!isFound) alert("This site\\page isn't supported by the bookmarklet.");
}
(function ()
{
if (typeof(jQuery)!="undefined")
window.$ = jQuery;
var s=document.createElement('script');
s.setAttribute('src',"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
s.onload=wikiit;
try {
document.getElementsByTagName('body')[0].appendChild(s);
}
catch (e) {
document.getElementsByTagName('head')[0].appendChild(s);
}
})();