משתמש:מוטי בוט/ניסוי1.js
מראה
לתשומת ליבך: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
//הסקריפט נכתב על ידי [[משתמש:מקוה]] עבור המכלול, כל הזכויות על הסקריפט שמורות למכון חכמת התורה אסור להעתיק את הסקריפט או חלקים ממנו ללא אישור מראש ובכתב
const lang = "he",
sites = "hewiki";
const templates = [
{
name: `ויקישיתוף בשורה`,
regExp: /\{\{ויקישיתוף\sבשורה\s?\|?\s?(תצוגה[^}\n]+)?\}\}/,
parameters: [{ claim: "P373", param: "", text: "Category:" }],
},
{
name: "מיזמים",
regExp: /\{\{מיזמים\|?\}\}/,
parameters: [{ claim: "P373", param: "ויקישיתוף", text: "Category:" }],
},
{
name: `מידע טקסונומי`,
regExp: /\{\{מידע\sטקסונומי\s?\|?\s?\}\}/,
parameters: [
{ claim: "P815", param: "ITIS", text: "" },
{ claim: "P685", param: "NCBI", text: "" },
{ claim: "P4024", param: "Animal Diversity Web", text: "" },
{ claim: "P2833", param: "ARKive", text: "" },
{ claim: "P830", param: "האנציקלופדיה של החיים", text: "" },
{ claim: "P938", param: "FishBase", text: "" },
{ claim: "P3099", param: "Internet Bird Collection", text: "" },
{ claim: "P3746", param: "צמח השדה", text: "" },
{ claim: "P3795", param: "צמחיית ישראל ברשת", text: "" },
{ claim: "P960", param: "Tropicos", text: "" },
{ claim: "P846", param: "GBIF", text: "" },
{ claim: "P1070", param: "TPList", text: "" },
{ claim: "P961", param: "IPNI", text: "" },
],
},
{
name: `קישורי סינגלים`,
regExp: /\{\{קישורי סינגלים\s?\|?\s?\}\}/,
parameters: [
{ claim: "P435", param: "MusicBrainz1", text: "" },
{ claim: "P436", param: "MusicBrainz2", text: "" },
{ claim: "P1730", param: "AllMusic1", text: "" },
{ claim: "P1994", param: "AllMusic2", text: "" },
{ claim: "P1954", param: "Discogs", text: "" },
{ claim: "P3838", param: "Tab4u", text: "" },
{ claim: "P6218", param: "Genius", text: "" },
{ claim: "P2908", param: "SecondHandSongs", text: "" },
{ claim: "P1651", param: "YouTube", text: "" },
{ claim: "P2281", param: "iTunes", text: "" },
{ claim: "P3996", param: "nli", text: "" },
{ claim: "P4072", param: "zemereshet", text: "" },
{ claim: "P8201", param: "acum", text: "" },
{ claim: "P2205", param: "spotify1", text: "" },
{ claim: "P2207", param: "spotify2", text: "" },
{ claim: "P4577", param: "tidal", text: "" },
{ claim: "P4035", param: "shironet", text: "" },
],
},
{
name: `בריטניקה`,
regExp: /\{\{בריטניקה\s?\|?\s?\}\}/,
parameters: [{ claim: "P1417", param: "", text: "" }],
},
{
name: `Find a Grave`,
regExp: /\{\{(?:Find\sa\sGrave|Findagrave|מצא\sקבר)\s?\|?\}\}/,
parameters: [{ claim: "P535", param: "", text: "" }],
},
{
name: `אתר רשמי`,
regExp: /\{\{אתר\sרשמי\s?\|?(\|\|[^}]*)?\s?\}\}/,
parameters: [{ claim: "P856", param: "", text: "" }],
},
{
name: `רשתות חברתיות`,
regExp: /\{\{רשתות\sחברתיות\s?\|?\s?\}\}/,
parameters: [
{ claim: "P2013", param: "פייסבוק", text: "" },
{ claim: "P2002", param: "טוויטר", text: "" },
{ claim: "P2003", param: "אינסטגרם", text: "" },
{ claim: "P7085", param: "טיקטוק", text: "" },
{ claim: "P3185", param: "VK", text: "" },
{ claim: "P3789", param: "טלגרם", text: "" },
{ claim: "P6634", param: "לינקדין1", text: "" },
{ claim: "P4264", param: "לינקדין2", text: "" },
{ claim: "P2397", param: "יוטיוב", text: "" },
{ claim: "P5797", param: "טוויצ'", text: "" },
{ claim: "P4015", param: "וימאו", text: "" },
{ claim: "P1581", param: "בלוג", text: "" },
],
},
{
name: `פרופילי מדענים`,
regExp: /\{\{פרופילי\sמדענים\s?\|?\s?\}\}/,
parameters: [
{ claim: "P8024", param: "פרס נובל", text: "" },
{ claim: "P549", param: "פרויקט הגנאלוגיה במתמטיקה", text: "" },
{ claim: "P1563", param: "MacTutor", text: "" },
{ claim: "P2030", param: `נאס"א`, text: "" },
{ claim: "P2456", param: "dblp", text: "" },
{ claim: "P2038", param: "ResearchGate", text: "" },
{ claim: "P1960", param: "גוגל סקולר", text: "" },
{ claim: "P5715", param: "Academia", text: "" },
{ claim: "P6479", param: "IEEE", text: "" },
{ claim: "P3747", param: "SSRN", text: "" },
{ claim: "P3874", param: "Justia", text: "" },
],
},
{
name: `פרופילי מוזיקאים`,
regExp: /\{\{פרופילי\sמוזיקאים\s?\|?\s?\}\}/,
parameters: [
{ claim: "P4071", param: "זמרשת", text: "" },
{ claim: "P4034", param: "שירונט", text: "" },
{ claim: "P2850", param: "iTunes", text: "" },
{ claim: "P1902", param: "Spotify", text: "" },
{ claim: "P3040", param: "SoundCloud", text: "" },
{ claim: "P3192", param: "Last", text: "" },
{ claim: "P1287", param: "Komponisten", text: "" },
{ claim: "P1728", param: "AllMusic", text: "" },
{ claim: "P434", param: "MusicBrainz", text: "" },
{ claim: "P1989", param: "MetallumA", text: "" },
{ claim: "P1952", param: "MetallumB", text: "" },
{ claim: "P2164", param: "SIGIC", text: "" },
{ claim: "P2514", param: "Jamendo", text: "" },
{ claim: "P2722", param: "דיזר", text: "" },
{ claim: "P1553", param: "יאנדקס", text: "" },
{ claim: "P3674", param: "מוטופיה", text: "" },
{ claim: "P1953", param: "Discogs", text: "" },
{ claim: "P3478", param: "Songkick", text: "" },
{ claim: "P3839", param: "Tab4u", text: "" },
{ claim: "P2373", param: "Genius", text: "" },
{ claim: "P3952", param: "סטריאו ומונו", text: "" },
{ claim: "P3997", param: "בית לזמר", text: "" },
{ claim: "P2909", param: "SecondHandSongs", text: "" },
{ claim: "P2510", param: "DNCI", text: "" },
{ claim: "P3283", param: "בנדקמפ", text: "" },
{ claim: "P4208", param: "בילבורד", text: "" },
],
},
{
name: `פרופילי אנציקלופדיות`,
regExp: /\{\{פרופילי\sאנציקלופדיות\s?\|?\}\}/,
parameters: [
{ claim: "P8590", param: "האנציקלופדיה היהודית", text: "" },
{ claim: "P12134", param: "מסע אל העבר", text: "" },
{ claim: "P3710", param: "דעת", text: "" },
{ claim: "P10717", param: "אנציקלופדיה של הרעיונות", text: "" },
{ claim: "P1296", param: "האנציקלופדיה הקטלאנית", text: "" },
{ claim: "P6337", param: "Half-Life 2", text: "" },
{ claim: "P2812", param: "MathWorld", text: "" },
{ claim: "P3012", param: "אנציקלופדיה איראניקה", text: "" },
{
claim: "P5088",
param: "אנציקלופדיה אינטרנטית לפסיכולוגיה",
text: "",
},
{ claim: "P1417", param: "בריטניקה", text: "" },
],
},
{
name: `פרופילי חברות`,
regExp: /\{\{פרופילי\sחברות\s?\|?\s?\}\}/,
parameters: [
{ claim: "P2088", param: "Crunchbase", text: "" },
{ claim: "P5531", param: "EDGAR", text: "" },
],
},
{
name: `מידע בורסאי`,
regExp: /\{\{מידע\sבורסאי\s?\|?\s?\}\}/,
parameters: [
{ claim: "P2088", param: "Crunchbase", text: "" },
{ claim: "P3377", param: "בלומברג", text: "" },
],
} /*
{
name: `מידע בורסאי (ארצות הברית)`,
regExp: /\{\{מידע\sבורסאי\sארצות\sהברית\s?\|?\s?\}\}/,
parameters: [
{ claim: "P414", param: "", text: "" },
],
parametersText: [],
textToReplace: null,
},*/,
{
name: `מידע בורסאי (לונדון)`,
regExp: /\{\{מידע\sבורסאי\s(לונדון)\s?\|?\s?\}\}/,
parameters: [{ claim: "P2088", param: "Crunchbase", text: "" }],
parametersText: [],
},
{
name: `ביו-קונגרס`,
regExp: /\{\{ביו\-קונגרס\s?\|?\s?\}\}/,
parameters: [{ claim: "P1157", param: "", text: "" }],
},
{
name: `ביו-נובל`,
regExp: /\{\{ביו\-נובל\s?\|?\s?\}\}/,
parameters: [{ claim: "P8024", param: "", text: "" }],
},
{
name: `ביו-נאס"א`,
regExp: /\{\{ביו\-נאס\"א\s?\|?\s?\}\}/,
parameters: [{ claim: "P2030", param: "", text: "" }],
},
{
name: `MathWorld`,
regExp: /\{\{MathWorld\s?\|?\s?\}\}/,
parameters: [{ claim: "P2812", param: "", text: "" }],
},
{
name: `גיידסטאר`,
regExp: /\{\{גיידסטאר\s?\|?\s?\}\}/,
parameters: [{ claim: "P3914", param: "", text: "" }],
},
{
name: `SIMBAD`,
regExp: /\{\{SIMBAD\s?\|?\s?\}\}/,
parameters: [{ claim: "P3083", param: "", text: "" }],
},
{
name: `אתר החכם היומי`,
regExp: /\{\{אתר\sהחכם\sהיומי\s?\|?\s?\}\}/,
parameters: [{ claim: "P10776", param: "", text: "" }],
},
{
name: `CIA factbook`,
regExp: /\{\{CIA factbook\s?\|?\s?\}\}/,
parameters: [{ claim: "P9948", param: "", text: "" }],
},
{
name: `אנציקלופדיית ההיסטוריה העולמית`,
regExp: /\{\{אנציקלופדיית ההיסטוריה העולמית\}\}/,
parameters: [{ claim: "P9000", param: "", text: "" }],
},
{
name: `שם בשפת המקור`,
regExp: /\{\{שם\sבשפת\sהמקור\s?\|?\s?\}\}/,
parameters: [
{ claim: "P1559", param: "שם", text: "" },
{ claim: "P1559", param: "שפה", text: "" },
{ claim: "P443", param: "קובץ", text: "" },
],
},
{
name: `דף שער בספרייה הלאומית`,
regExp: /\{\{דף שער בספרייה הלאומית\}\}/,
parameters: [{ claim: "P3997", param: "", text: "" }],
},
{
name: `אנצ יהודית`,
regExp: /\{\{אנצ יהודית\}\}/,
parameters: [{ claim: "P8590", param: "", text: "" }],
},
];
async function textChecki(title, text) {
console.log("checking");
const regExp = new RegExp(
templates.map((template) => template.regExp.source).join("|"),
"g"
);
if (regExp.test(text)) {
return await getPageNo(title, text);
}
console.log("nothing to change");
}
const getParameter = (claims, parameter) => {
const { claim, param, text } = parameter;
if (!claims[claim]) return null;
let data;
if (claim === "P1559") {
data =
param === "שפה"
? claims["P1559"][0].mainsnak.datavalue.value.language
: claims["P1559"][0].mainsnak.datavalue.value.text.replace(
/\=/g,
"{{=}}"
);
} else {
data = claims[claim][0].mainsnak.datavalue?.value.replace(/\=/g, "{{=}}");
if (!data) {
console.error(claims[claim][0]);
data = "";
}
}
return param && text
? `|${param}=${text}${data}`
: param
? `|${param}=${data}`
: text
? `|${text}${data}`
: `|${data}`;
};
const generateTemplateTexts = (template, claims) => {
const parametersText = template.parameters
.filter((parameter) => claims && claims[parameter.claim])
.map((parameter) => getParameter(claims, parameter))
.filter((text) => text !== null);
if (parametersText.length) {
return template.name + parametersText.join("");
}
return null;
};
const addTextToReplace = (num, claims) => {
const template = templates[num];
const textToReplace = generateTemplateTexts(template, claims);
if (textToReplace) {
template.textToReplace = textToReplace;
}
};
async function getPageNo(title, text) {
const wikiDataPropId = `https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&sites=${sites}&titles=${encodeURIComponent(
title
)}&props=labels|descriptions&languages=${lang}&utf8=1&origin=*`;
const res = await fetch(wikiDataPropId);
const data = await res.json();
if (!data.entities) return console.log("no wikidata prop found");
for (const e in data.entities) {
if (!e) return console.log("no wikidata prop found");
return await getClaimsi(e, text);
}
}
function getAnotherMeaning(description) {
if (
"descriptions" in description === false ||
!description.descriptions ||
"he" in description.descriptions === false ||
!description.descriptions.he ||
"value" in description.descriptions.he === false
) {
return;
}
const template = {
name: `פירוש נוסף`,
regExp: /\{\{פירוש\sנוסף\s?\|?\s?\}\}/,
parameters: [{ claim: "", param: "נוכחי", text: "" }],
};
if (!template.regExp.test($("#wpTextbox1").val())) return;
$("#wpTextbox1").val(
$("#wpTextbox1")
.val()
.replace(
template.regExp,
`{{${template.name}|נוכחי=${description.descriptions.he.value}}}`
)
);
}
async function getClaimsi(entity, text) {
const res = await fetch(
`https://www.wikidata.org/w/api.php?action=wbgetclaims&format=json&entity=${entity}&utf8=1&origin=*`
);
const data = await res.json();
for (let a = 0; a < templates.length; a++) {
addTextToReplace(a, data.claims);
}
return replaceText(text);
}
function replaceText(text) {
let newText = text;
templates.forEach((template) => {
if (!template.textToReplace) return;
newText = newText.replace(template.regExp, (match, ...args) => {
// console.log([match, ...args]);
const captureGroups = args.slice(0, args.length - 2);
if (captureGroups.length) {
//console.log(captureGroups);
captureGroups.forEach((group) => {
if (group) {
//console.log(group);
template.textToReplace += group;
}
});
}
return `{{${template.textToReplace}}}`;
});
});
if (newText !== text) {
console.log("change is done");
}
return newText;
}