OneTime layout saver

Save and restore column layouts for OneTime

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        OneTime layout saver
// @description Save and restore column layouts for OneTime
// @namespace   https://greasyfork.org/en/users/814-bunta
// @version     1.1
// @include     https://onetime.onedatacom.com/*
// @run-at      document-end
// @noframes
// @nowrap
// @libraries   
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

console.log("script start");

var $ = unsafeWindow.$;
var widths1 = JSON.parse(GM_getValue("savedWidths1", "[30,215,250,80,240,70,65,40]"));
var widths2 = JSON.parse(GM_getValue("savedWidths2", "[30,215,250,80,240,70,65,40]"));

function loadFavouritesColumnLayout() {
  $("div#onejobgrid colgroup").each(function() {
    $(this).children().each(function(i) {
      $(this).removeAttr('style').css("width",widths1[i]+"px");
    });
  });
  
  $("div#buFavgrid colgroup").each(function() {
    $(this).children().each(function(i) {
      $(this).removeAttr('style').css("width",widths2[i]+"px");
    });
  });

}

function addSaveButton() {
  var elem = document.getElementById("saveLayoutBtn"); 
  elem.onclick = saveFavouritesColumnLayout;
}

function saveFavouritesColumnLayout() {
  var widthSettings = [];
  $("div#onejobgrid colgroup").first().children().each(function(i) {
    widthSettings.push($(this).width());
  });
  
  GM_setValue("savedWidths1", JSON.stringify(widthSettings));

  var widthSettings = [];
  $("div#buFavgrid colgroup").first().children().each(function(i) {
    widthSettings.push($(this).width());
  });
  
  GM_setValue("savedWidths2", JSON.stringify(widthSettings));
}

loadFavouritesColumnLayout();
addSaveButton();

console.log("script finish");