Last active
November 30, 2023 14:56
-
-
Save CEBracco/079d7432d6dcfaabacad0be663c851c9 to your computer and use it in GitHub Desktop.
Userscripts para facilitar el uso de la ventana de asignacion de permisos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name FunctionUtils | |
// @namespace http://tampermonkey.net/ | |
// @version 1.2 | |
// @updateURL https://gist.github.com/CEBracco/079d7432d6dcfaabacad0be663c851c9/raw/284214613d7246c2ed631e9a9a719104b5b7a76d/FunctionUtils.user.js | |
// @description Facilita el uso de la ventana de asignacion de permisos | |
// @author cbracco | |
// @match *://*.movypark.com | |
// @match *://*.dat.cespi.unlp.edu.ar | |
// @match http://163.10.20.80/universe-web/ | |
// @match *://*.gob.ar | |
// @match *://*.gov.ar | |
// @match https://semlamatanza.com.ar | |
// @match https://sem.estacionamientojunin.com.ar/ | |
// @match *://*.parxin.com.py/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
/** | |
* Userscripts para facilitar el uso de la ventana de asignacion de permisos | |
* | |
* NOTA: usar en la ventana de asignacion de permisos listando todos (escribir en el buscador "aa|") | |
* | |
* Métodos: | |
* functionsLenght(): devuelve la cantidad de permisos asignados al usuario | |
* obtainKeys(): obtiene un json con las claves de los permisos asignados al usuario | |
* checkFunctions(functions): asigna todos los permisos especificados en el objeto pasado por parámetro | |
* clearFunctions(): deschequea todas las casillas de funciones | |
* replaceFunctions(functions): reemplaza todos los permisos por los especificados en el objeto pasado por parámetro | |
* functionsDiff(uf1Json,uf2Json): devuelve un array con la diferencia de los jsons de permisos de los usuarios | |
* | |
*/ | |
function functionsLenght(){ | |
return $("input[type='checkbox']:checked").length; | |
} | |
function obtainKeys(stringify = false){ | |
var keys= []; | |
$("input[type='checkbox']:checked").each(function(){ | |
keys.push($(this).closest('tr').find('th').first().text()); | |
}); | |
return stringify ? JSON.stringify({keys:keys}) : {keys:keys}; | |
} | |
function checkFunctions(functions){ | |
for (var key of functions.keys) { | |
var functionCheckbox = $( "tr:contains('"+ key +"')" ).find("input[type='checkbox']"); | |
if(!functionCheckbox.is(':checked')){ | |
functionCheckbox.click(); | |
} | |
} | |
} | |
function clearFunctions(){ | |
$("input[type='checkbox']:checked").click(); | |
} | |
function replaceFunctions(functions){ | |
clearFunctions(); | |
checkFunctions(functions); | |
} | |
// interno usado por functionsDiff() | |
function arr_diff (a1, a2) { | |
var a = [], diff = []; | |
for (var i = 0; i < a1.length; i++) { | |
a[a1[i]] = true; | |
} | |
for (var j = 0; j < a2.length; i++) { | |
if (a[a2[j]]) { | |
delete a[a2[j]]; | |
} else { | |
a[a2[j]] = true; | |
} | |
} | |
for (var k in a) { | |
diff.push(k); | |
} | |
return diff; | |
} | |
function arr_diff2(a1, a2){ | |
var a2Set = new Set(a2); | |
return a1.filter(function(x) { return !a2Set.has(x); }); | |
} | |
function functionsDiff(uf1Json,uf2Json){ | |
var uf1 = uf1Json; | |
var uf2 = uf2Json; | |
return arr_diff2(uf1.keys,uf2.keys); | |
} | |
function functionsDiff2(uf1Json,uf2Json){ | |
var uf1 = uf1Json; | |
var uf2 = uf2Json; | |
var diff = []; | |
for (var key of uf1.keys) { | |
console.log(uf2.keys.indexOf(key)); | |
if(uf2.keys.indexOf(key) === -1){ | |
diff.push(key); | |
} | |
} | |
return diff; | |
} | |
var functionUtils = {} | |
functionUtils.functionsLenght = functionsLenght; | |
functionUtils.obtainKeys = obtainKeys; | |
functionUtils.checkFunctions = checkFunctions; | |
functionUtils.replaceFunctions = replaceFunctions; | |
functionUtils.functionsDiff = functionsDiff; | |
functionUtils.clearFunctions = clearFunctions; | |
window.functionUtils = functionUtils; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment