משתמש:Yonidebest/scripts/loadTemplates.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/* adds link to toolbox which shows links to templates in page.
 * shallow-tested on ie8
 * 
 * written by [[user:yonidebest]]
 */
 
function templateLinks(title)
{
	var temp = '<li><a href="/wiki/' + encodeURIComponent(title) + '" title="' + title + '">' + title + '</a> ';
	temp += '(<a href="/wiki/' + encodeURIComponent("שיחת " + title) + '" title="שיחת ' + title + '">שיחה</a> | ';
	temp += '<a href="/w/index.php?title=' + encodeURIComponent(title) + '&action=edit" title="עריכת ' + title + '">עריכה</a> | ';
	temp += '<a href="/w/index.php?title=' + encodeURIComponent(title) + '&action=history" title="גרסאות קודמות של ' + title + '">גרסאות קודמות</a>)';
	temp += '</li>';
	return temp;
}

function loadTemplates()
{
	var a = sajax_init_object();
	a.open('GET', 'http://he.wikipedia.org/w/api.php?action=query&prop=templates&titles=' + encodeURIComponent(mw.config.get('wgPageName')), true);
	a.onreadystatechange = function() {
		if (a.readyState != 4) return;

		// populate template list
		var templateList = [];
		var rx = new RegExp('title=&quot;(.*)&quot; /&gt;', 'g');
		var m = rx.exec(a.responseText);
		while (m)
		{
			templateList.push(m[1].replace(/&quot;/g, '"'));
			m = rx.exec(a.responseText);
		}
		
		var liList = document.createElement('span');
		if (templateList.length == 0)
		{
			// no templates
			liList.innerHTML = '<span style="color: red;">בדף זה אין תבניות.</span>';
			
		} else {
		
			// create links
			liList.innerHTML = 'להלן תבניות שנמצאו בדף זה:<br /><ul>';
			for (var i = 0; i < templateList.length; i++)
				liList.innerHTML += templateLinks(templateList[i]);
			liList.innerHTML += '</ul>';
			
		}

		// show links/message
		var siteSub = document.getElementById('siteSub');
		
		siteSub.parentNode.insertBefore(liList, siteSub);
		
		// jump to top of the page
		scrollTo(0, 0);
	}
	a.send(null);
}

$(
	function()
	{
		mw.util.addPortletLink("p-tb", "javascript:loadTemplates();", "הצגת תבניות", "pt-js-templatelist", "הצג תבניות המוצגות בדף זה", "", "");
	}
);