מדיה ויקי:Gadget-directlink-to-commons.js
קפיצה לניווט
קפיצה לחיפוש
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload), או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh), או ללחוץ על צירוף המקשים Ctrl-F5.
- אופרה: ללחוץ על Ctrl-F5.
/** * Direct imagelinks to Commons * * Required modules: mediawiki.util * * @source https://www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons * @author Krinkle * @version 2022-09-06 */ if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) { mw.loader.using( [ 'mediawiki.util' ] ).then( function () { mw.hook( 'wikipage.content' ).add( function ( $content ) { var uploadBaseRe = /^(https:)?\/\/upload\.wikimedia\.org\/wikipedia\/commons/, localFileNSString = mw.config.get( 'wgFormattedNamespaces' )['6'] + ':', localBasePath = new RegExp( '^' + mw.util.escapeRegExp( mw.util.getUrl( localFileNSString ) ) ), localBaseScript = new RegExp( '^' + mw.util.escapeRegExp( mw.util.wikiScript() + '?title=' + mw.util.wikiUrlencode( localFileNSString ) ) ), commonsBasePath = 'https://commons.wikimedia.org/wiki/File:', commonsBaseScript = 'https://commons.wikimedia.org/w/index.php?title=File:'; $content.find( 'a.image, a.mw-file-description' ).attr( 'href', function ( i, currVal ) { if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) { return currVal .replace( localBasePath, commonsBasePath ) .replace( localBaseScript, commonsBaseScript ); } } ); } ); } ); }