Usuari:Gerardduenas/Gadget-fop.js

De la Viquipèdia, l'enciclopèdia lliure

Nota: Després de desar, heu de netejar la memòria cau del navegador per veure els canvis. En la majoria de navegadors amb Windows o Linux, premeu Ctrl+F5 o bé premeu Shift i cliqueu el botó "Actualitza" (Ctrl i "Actualitza" amb Internet Explorer). Vegeu més informació i instruccions per a cada navegador a Viquipèdia:Neteja de la memòria cau.

$( function () {
	//document.cookie="gadget-fop=; expires=Thu, 01 Jan 1970 01:00:0 UTC; path=/";
	'use strict';
	if (!checkCookie()){
		if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
			$( '#mw-content-text img' ).each( function () {
				if ( $( this ).attr( 'src' ).match( /^(?:(?!\.svg\.png).)*$/i ) && $( this ).attr( 'height' ) > 40 ) {
					$( this ).parent( 'a' ).replaceWith( '<div class="gadget-fop" style="display: table-cell; vertical-align: middle; height: ' + $( this ).attr( 'height' ) + 'px; width: ' + $( this ).attr( 'width' ) + 'px;">La llibertat de panorama està en perill!<br>—<a href="https://ca.wikipedia.org/wiki/Viquip%C3%A8dia:Llibertat_de_panorama_d%27Europa">Més informació</a><br>—<a href="'+ $( this ).parent( 'a' ).attr('href') +'">Vés a la imatge</a><br><div id="cookie">—<a href="javascript:setCookie()">Ho entenc, no amaguis més les imatges</a> <small>(cal tenir les cookies activades)<small></div></div>' );
				}
			} );
		}
	}
} );
function setCookie () {
	document.cookie = "gadget-fop=false; expires=Thu, 9 Jul 2015 23:00:00 UTC; path=/";
	location.reload();
}
function getCookie () {
    var name = "gadget-fop=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}
function checkCookie() {
    var cookie=getCookie("gadget-fop");
    if (cookie!="") {
        return true;
    }else{
        return false;
    }
}