Usuari:Vriullop/vector.js

De Viccionari

Nota: Després de publicar, possiblement necessitareu refrescar la memòria cau del vostre navegador per a veure'n els canvis.

  • Firefox / Safari: Premeu Majús i alhora cliqueu el botó Actualitzar, o pressioneu Ctrl+F5 o Ctrl+R (⌘+R en un Mac)
  • Google Chrome: Premeu Ctrl+Majús+R (⌘+Shift+R en un Mac)
  • Internet Explorer / Edge: Premeu Ctrl i alhora cliqueu a Actualitza o pressioneu Ctrl+F5
  • Opera: Premeu Ctrl-F5.
//mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Brion_VIBBER/mobile-sidebar.css&action=raw&ctype=text/css', 'text/css');
//mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Brion_VIBBER/mobile-sidebar.js&action=raw&ctype=text/javascript');

mw.loader.load('//de.wiktionary.org/w/index.php?title=MediaWiki:Gadget-rhymesedit.js&action=raw&ctype=text/javascript','text/javascript',false);

// traducció categoria de.wikt
jQuery(window).ready(function(){
	var ns=mw.config.get("wgNamespaceNumber");
	if((ns==14) && mw.config.get("wgAction")=="view")
	{
		//if(mw.config.get("wgTitle").substr(0,17)=="Diccionari invers")
		var elements = document.getElementsByClassName("catrtl");
		if (elements.length > 0)
		{
			$("#mw-pages h3").attr("dir", "rtl").attr("style", "margin-right: 1em").wrapInner("<span dir='ltr'></span>");
			$("#mw-pages ul").attr("dir", "rtl").attr("style", "margin-right: 2em");
			$("#mw-pages li").wrapInner("<span dir='ltr'></span>");
		}
	}
});

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:Pathoschild/templatescript.js]]
 */
//mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add([
		// add your own templates or scripts here
		//{ name: 'welcome', template: '{{subst:welcome}} [[Usuari:Vriullop|Vriullop]] ([[Usuari Discussió:Vriullop|discussió]]) 12:08, 7 abr 2017 (CEST)', position: 'after', editSummary: 'welcome!', forNamespaces: 'user talk' },
		{
			name: 'traduccions',
			script: function(editor) {
				editor.replaceSelection(function(selected){
					return '{{-trad-}}\n{{t-inici}}\n\* {{en}}: {{trad|en|xxx}}\n\* {{es}}: {{trad|es|xxx}}\n\* {{fr}}: {{trad|fr|xxx}}\n\* {{it}}: {{trad|it|xxx}}\n{{t-final}}\n';
				});
			}
		},
		{
			name: 'miscel·lània',
			script: function(editor) {
				editor.replaceSelection(function(selected){
					return '=== Miscel·lània ===\n* {{ca-sil}}\n';
				});
			}
		},
	]);
});

/**
 * Gadget to link Wiktionary and Wikidata Lexemes
 * https://www.wikidata.org/wiki/Wikidata_talk:Lexicographical_data#Gadget_to_link_Wiktionary_and_Wikidata
 */

//mw.loader.load("//fr.wiktionary.org/w/index.php?title=/Utilisateur:VIGNERON/LienLex.js?action=raw&ctype=text/javascript");

/**
 * Categories per seccions de llengua
 * From https://dpaste.com/ANRX92RAF, adaptat a ca.wikt
 * Released under the terms of the Creative Commons Zero (CC0) license.
 */

$(document).ready(function() {
	var langNames = [];
	
	function lowerCaseFirstLetter(string) {
		return string.charAt(0).toLowerCase() + string.slice(1);
	}
	
	var headlines = $("h2 .mw-headline");
	if (headlines.length < 2) return;
	for (var i = 0; i < headlines.length; i++) {
		langNames.push(lowerCaseFirstLetter(headlines[i].textContent));
	}
	
	function catLanguage(cat, num) {
		return cat.endsWith(langNames[num]) || cat.includes("en " + langNames[num]);
	}
	
	var categories = $("#mw-normal-catlinks").find("li");
	var newCategories = {
		"-1": []
	};
	var langNum = -1;
	for (var i = 0; i < categories.length; i++) {
		if (catLanguage(categories[i].textContent, langNum + 1)) {
			langNum++;
			newCategories["" + langNum] = [];
		}
		
		newCategories["" + langNum].push(categories[i]);
	}
	
	if (!newCategories[0]) return;
	
	for (var i = 0; i < langNames.length; i++) {
		var elements = $(headlines[i].parentElement).nextUntil("h2");
		
		var catBar = $('<div class="catlinks"><div class="mw-normal-catlinks"><a href="/wiki/Especial:Categories" title="Especial:Categories">Categories</a>: <ul style="margin:0">');
		
		for (var j = 0; j < newCategories["" + i].length; j++) {
			newCategories["" + i][j].remove();
			catBar.find("ul").append(newCategories["" + i][j]);
		}
		
		catBar.insertAfter(elements[elements.length - 1]);
	}
});