Skip to content

Instantly share code, notes, and snippets.

@sinux-l5d
Created October 11, 2024 13:01
Show Gist options
  • Save sinux-l5d/05d81f53c683aefefcd5d049441598d2 to your computer and use it in GitHub Desktop.
Save sinux-l5d/05d81f53c683aefefcd5d049441598d2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Fixed TE Web
// @namespace http://teweb.fr.sogeti.com/
// @version 0.7
// @description A better TE Web
// @author Robin Brisa
// @match https://teweb.fr.sogeti.com/*
// @updateURL https://checkit.connect.local/exports/teweb.user.js
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.deleteValue
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js
// ==/UserScript==
$(function()
{
var codeHistory = {};
var historyDays = 60;
var historyDelay = historyDays*24*60*60*1000;
var copiedBU;
var copiedProject;
(async function() {
codeHistory = await GM.getValue('codeHistory', {});
$("#container").append("<div id='history' style='margin-left: 10px'></div>");
if (Object.keys(codeHistory).length) {
$("#history").append("<p style='font-weight:bold; margin:10px 0; font-size:14px; '>Codes utilisés durant les " + historyDays + " derniers jours :</p>");
$.each(codeHistory, function(key, value) {
if (Date.now() - value.lastUse < historyDelay) {
$.each(value.relatedProjects, function(k, v) {
$("#history").append("<div style='margin-bottom:2px;'><span class='copyBU' style='font-weight:bold; cursor: pointer;'>" + key + "</span> - <span class='copyProject' style='cursor: pointer;'>" + v + "</span></div>");
});
}
});
}
})();
$("body").append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.css" integrity="sha256-xqxV4FDj5tslOz6MV13pdnXgf63lJwViadn//ciKmIs=" crossorigin="anonymous" />');
$("#ctl00_cph_a_upBtns").append('<input type="button" name="convert-select2" value="Convertir les champs" id="convert-select2" style="margin-right: 4px;">');
$("#ctl00_cph_a_upBtns").append('<input type="button" name="clear-history" value="Effacer historique" id="clear-history">');
$( document ).ready(function() {
$('<input id="prevMonth" type="button" style="margin-right:3px; font-size:12px; font-weight:bold; height:20px;" value="<"/> ').insertBefore("#ctl00_cph_w_ddlMonth");
$('<input id="nextMonth" type="button" style="margin-left:3px; font-size:12px; font-weight:bold; height:20px;" value=">"/>').insertAfter("#ctl00_cph_w_ddlMonth");
convert(200);
});
$(document).on('submit', function() {
convert(350);
})
$(document).on('change', 'select', function() {
convert(500);
});
$(document).on('click', '#clear-history', function() {
clearHistory();
});
$(document).on('click', '#convert-select2', function() {
convert(0);
});
$(document).on('click', '#prevMonth', function() {
$('#ctl00_cph_w_ddlMonth option:selected').prev().attr('selected', 'selected');
$('#ctl00_cph_w_ddlMonth').trigger('change');
});
$(document).on('click', '#nextMonth', function() {
$('#ctl00_cph_w_ddlMonth option:selected').next().attr('selected', 'selected');
$('#ctl00_cph_w_ddlMonth').trigger('change');
});
$(document).on('click', '.copyBU', function() {
$('.copyBU').css('background-color', '');
copiedBU = $(this).html();
$(this).css('background-color', 'yellow');
});
$(document).on('click', '.copyProject', function() {
$('.copyProject').css('background-color', '');
copiedProject = $(this).html();
$(this).css('background-color', 'yellow');
});
$(document).on('click', 'span[id*="ddlCodeBU"]', function() {
if (copiedBU) {
$(this).parents('td').find('select').val(copiedBU);
if ($(this).parents('td').find('select').val() == copiedBU) {
$('.copyBU').css('background-color', '');
$(this).parents('td').find('select').trigger('change').select2('close');
copiedBU = undefined;
}
}
});
$(document).on('click', "span[id*='ddlProjet']", function() {
if (copiedProject) {
var optionValue = $(this).parents('td').find('option:contains("'+copiedProject+'")').attr('value');
$(this).parents('td').find('select').val(optionValue);
if (optionValue) {
$('.copyProject').css('background-color', '');
copiedProject = undefined;
$(this).parents('td').find('select').trigger('change').select2('close');
}
}
});
$(document).on('click', "select", function() {
convert(0);
});
$("#ctl00_cph_a_btnEnregistrer").click(function() {
$("select[name*='ddlCodeBU'] option:selected").each(function() {
var BUCode = $(this).text();
var projectCode = $(this).parents('tr').find("select[name*='ddlProjet'] option:selected").text();
if (!(BUCode in codeHistory)) {
codeHistory[BUCode] = { 'BUCode': BUCode, lastUse: Date.now(), 'relatedProjects': [] };
} else {
codeHistory[BUCode].lastUse = Date.now();
}
if (!codeHistory[BUCode].relatedProjects.includes(projectCode) && projectCode != "") {
codeHistory[BUCode].relatedProjects.push(projectCode);
}
GM.setValue('codeHistory', codeHistory);
});
});
function clearHistory() {
codeHistory = {};
GM.deleteValue('codeHistory');
$("#history").html("");
}
function convert(delay) {
setTimeout(function() {
$("select").each(function() {
if (!$(this).data('select2') && $(this).attr('id') != "ctl00_cph_w_ddlMonth") {
$(this).select2();
}
});
},delay);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment