מדיה ויקי:סקריפטים/105.js
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
/** * Simple script for easy translation of wikidata labels */ $(function(){ if (!$( 'a.wb-entity-link[href*="Q"]' ).length) return; function translateLabel(e) { var entityId = /Q[0-9]+/.exec($(this).prev().prop('href')), hebrewLabel, repoApi; if (entityId) { entityId = entityId[0]; hebrewLabel = prompt('הזנת תווית עברית ל-'+ $(this).prev().text()); if (hebrewLabel) { mw.loader.using( [ 'wikibase.api.RepoApi', 'mw.config.values.wbRepo' ] ).done(function(){ var repoConfig = mw.config.get( 'wbRepo' ), repoApi = new wikibase.api.RepoApi( wikibase.api.getLocationAgnosticMwApi(repoConfig.url + repoConfig.scriptPath + '/api.php') ); repoApi.setLabel(entityId,0,hebrewLabel,'he').done(function(d){ if (d.success) mw.notify('התרגום נשמר!'); }) }); } } e.preventDefault(); } var translateLink = $('<span> [ <a href="#">תרגום</a> ]</span>').click( translateLabel ); $( 'a.wb-entity-link[href*="Q"]' ).filter( function( i, e ) { return /[a-z]/i.test( e.text ) } ).after( translateLink ); })