Skip to content

Commit

Permalink
Tab styling is applied with higher specificity, but plays nicer with …
Browse files Browse the repository at this point in the history
…other scripts as well
  • Loading branch information
Glodenox committed Jan 3, 2016
1 parent bd39392 commit 838b79e
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions WME_Tab_Preferences.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
// @include https://editor-beta.waze.com/*
// @exclude https://www.waze.com/user/*editor/*
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADcAAAA3CAYAAACo29JGAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wwCEzYBoD6dGgAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAACfUlEQVRo3u3aTUgUYRjA8b/bjKyziyyTH2VpKYoHDxLkaTFvRSJCeBHxpFBHCULoWgcpqL3VqZaQIIKULlKSBoqIGJjQQTE2T8YqbpCzrwuz63Zwxy5+pLTtzvY8txle5n1+PO/XDFP0c8tKU6DhoYBDcIITnOAE99/jtKMa2LaNUnGSts3Ozk5+VMTjQdN1jBIDvbj4wHZFh51QtpXCsrbyujo+nx/D5zte5Wzb3oOZponf70fTtLwAJZNJLMsiFosRj1vour5vBQ+cc0rF92CBQCBvYACaphEIBDBNczfXbXW8BSWVSgFgGEbeDkknNyfXP8clkwAUHzJhcx1Obk6uss8JTnCCy93x6+/FJgvvp1hVBhevXOPS6UKo3NoUI++WSDDHyMMQodBTJpbAmn/D6EIiq10feLbcWI8CUFdXd/KnJxZ4cusOr76BYZxCqQzGa2CkFIpaeh+/4GbzybuIRCIAlFdU/uPKeSs5X1UC2L9hAAmFsoGzLbQ0unJYWnz5MMemx7t7WRrk9vA4U2PPGQiWZpDf+Twxw1fLdbhJXt4LEZ5eB6CmvZsbF7zgr6eru50agPVpwg/u8mzSdbgKquvLMA19d63ciOIMzLXIKpsAuoFZdo7yUjcuKMBKuJ/+8AqgYzZeptmMsfhpmZgNtAww9qgLP25cUJhh9O2K8/pLbHmWj7MZGMD8ME9mXLvPBenta+NM7XUGh3poyNxt6Bli8Go15W199AZdfEKp6rzP606ARaJN4/yIVtHaGqSjKUhHlvvO+pzLduRwzslbgeAEJzjBCS6331CczdrtsZ+joCtXlE6n5Q8iwQlOcIITnOAEJzjBCe6I+AVAjNynsKm5WAAAAABJRU5ErkJggg==
// @version 1.0.2
// @version 1.0.3
// @grant none
// ==/UserScript==
"use strict";
(function() {
var tabReopened = false, // have we reopened the tab from last time?
timesRan = 0, // variable for sanity check
tabsSecured = -1, // Up until which index have we fully rearranged the tabs?
versions = ['0.1', '0.2', '1.0', '1.0.1', '1.0.2'],
versions = ['0.1', '0.2', '1.0', '1.0.1', '1.0.2', '1.0.3'],
Storage = (function() {
var hashes = (localStorage.tabprefs_hidden ? localStorage.tabprefs_hidden.split(',') : []),
tabConfigs = (localStorage.tabprefs_configs ? JSON.parse(localStorage.tabprefs_configs) : {});
Expand Down Expand Up @@ -80,7 +80,8 @@
v0_2: '- Improvements to order preservation algorithm\n- Addition of version change messages',
v1_0: '- Ability to hide a tab added\n- Ability to replace tab with symbol added\n- Ability to resize tabs added\n- Metadata icon added to userscript',
v1_0_1: '- Fixed the script for Google Chrome',
v1_0_2: '- Fixed tab size reset buttons in Google Chrome'
v1_0_2: '- Fixed tab size reset buttons in Google Chrome',
v1_0_3: '- Tab styling is applied with higher specificity, but plays nicer with other scripts as well'
}
},
nl: {
Expand Down Expand Up @@ -150,16 +151,20 @@
}
}
renameTabs();
resizeTabs();
reorderTabs();
if (localStorage.tabprefs_tabwidth || localStorage.tabprefs_tabheight) {
resizeTabs();
}
}
});
});
tabObserver.observe(tabs, { childList: true });
reopenTab();
renameTabs();
resizeTabs();
reorderTabs();
if (localStorage.tabprefs_tabwidth || localStorage.tabprefs_tabheight) {
resizeTabs();
}
}

function initSettings() {
Expand All @@ -176,14 +181,8 @@
heading.appendChild(document.createTextNode(I18n.t('tabpreferences.prefs.title')));
formGroup.className = 'form-group';
formGroup.style.marginBottom = '15px';
formGroup.appendChild(createSlider('tabWidth', I18n.t('tabpreferences.prefs.tab_width'), localStorage.tabprefs_tabwidth, 15, function() {
localStorage.tabprefs_tabwidth = this.value;
resizeTabs();
}));
formGroup.appendChild(createSlider('tabHeight', I18n.t('tabpreferences.prefs.tab_height'), localStorage.tabprefs_tabheight, 5, function() {
localStorage.tabprefs_tabheight = this.value;
resizeTabs();
}));
formGroup.appendChild(createSlider('tabWidth', I18n.t('tabpreferences.prefs.tab_width'), 'tabprefs_tabwidth', 15, resizeTabs));
formGroup.appendChild(createSlider('tabHeight', I18n.t('tabpreferences.prefs.tab_height'), 'tabprefs_tabheight', 5, resizeTabs));
formGroup.appendChild(createOption('reopenTab', I18n.t('tabpreferences.prefs.preserve_tab'), (localStorage.tabprefs_reopenTab ? true : false), function() {
if (this.checked) {
localStorage.tabprefs_reopenTab = document.querySelector('#user-tabs .nav-tabs li.active a').hash;
Expand Down Expand Up @@ -241,25 +240,30 @@
}

// Add sliders to the preferences tab
function createSlider(name, description, initialValue, defaultValue, eventHandler) {
function createSlider(name, description, storageKey, defaultValue, eventHandler) {
var input = document.createElement('input');
input.type = 'range';
input.name = name;
input.id = name + '-on';
input.min = 0;
input.max = 30;
input.value = (initialValue ? initialValue : defaultValue);
input.addEventListener('input', eventHandler);
input.value = (localStorage[storageKey] ? localStorage[storageKey] : defaultValue);
input.addEventListener('input', function() {
localStorage[storageKey] = this.value;
eventHandler();
});
input.style.verticalAlign = 'middle';
var label = document.createElement('label');
label.htmlFor = name + '-on';
label.appendChild(document.createTextNode(description));
label.style.marginRight = '4px';
var reset = document.createElement('button');
reset.className = 'btn-link';
reset.style.paddingRight = '0';
reset.addEventListener('click', function() {
input.value = defaultValue;
eventHandler.call(input);
localStorage.removeItem(storageKey);
eventHandler();
});
reset.appendChild(document.createTextNode(I18n.t('tabpreferences.prefs.reset')));
var container = document.createElement('div');
Expand Down Expand Up @@ -342,7 +346,7 @@
height = (localStorage.tabprefs_tabheight ? localStorage.tabprefs_tabheight : 5),
tabAnchors = document.querySelectorAll('#user-tabs .nav-tabs li a');
for (var i = 0; i < tabAnchors.length; i++) {
tabAnchors[i].style.padding = height + 'px ' + width + 'px';
tabAnchors[i].style.cssText += ';padding:' + height + 'px ' + width + 'px !important';
}
}

Expand Down

0 comments on commit 838b79e

Please sign in to comment.