Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This is an edited version of the common.js file from
- Deluminate 0.3.2_0, the Google Chrome extension. The
- changes that I made are exclusively in the function:
- getSiteScheme(). The purpose of these changes are to
- make it so that any rules set for a domain carry over
- to all subdomains, unless a rule is already set for
- that specific subdomain. You can still create rules
- for subdomains and they will be remembered as such
- without affecting the rules for any other subdomains.
- I added conditionals specifically to handle any website
- regardless of whether or not the primary domain is
- accessed starting with "www."
- In my testing, the GUI works as expected for those
- rule defining characteristics without needing to make
- any other alterations to any parts of Deluminate. I
- have not had anyone else test this yet, so if you see
- any issues or have any questions, feel free to contact
- me at soldier9599@gmail.com
- */
- var DEFAULT_SCHEME = "delumine-smart";
- function $(id) {
- return document.getElementById(id);
- }
- function getEnabled() {
- var result = localStorage['enabled'];
- if (result === 'true' || result === 'false') {
- return (result === 'true');
- }
- localStorage['enabled'] = 'true';
- return true;
- }
- function setEnabled(enabled) {
- localStorage['enabled'] = enabled;
- }
- function getKeyAction() {
- var keyAction = localStorage['keyaction'];
- if (keyAction == 'global' || keyAction == 'site') {
- return keyAction;
- }
- keyAction = 'global';
- localStorage['keyaction'] = keyAction;
- return keyAction;
- }
- function setKeyAction(keyAction) {
- if (keyAction != 'global' && keyAction != 'site') {
- keyAction = 'global';
- }
- localStorage['keyaction'] = keyAction;
- }
- function getDefaultScheme() {
- var scheme = localStorage['scheme'];
- if (scheme) {
- return scheme;
- }
- scheme = DEFAULT_SCHEME;
- localStorage['scheme'] = scheme;
- return scheme;
- }
- function setDefaultScheme(scheme) {
- if (!(scheme)) {
- scheme = DEFAULT_SCHEME;
- }
- localStorage['scheme'] = scheme;
- }
- function getSiteScheme(site) {
- var scheme = getDefaultScheme();
- try {
- var siteSchemes = JSON.parse(localStorage['siteschemes']);
- if (siteSchemes[site]) { // If it already matches a rule, follow it.
- scheme = siteSchemes[site]
- }
- else if (site.indexOf("www") == -1) { // If not a www and has no specific rule
- var newsite = site.substr(site.indexOf(".") + 1) // Remove lowest level domain for new url var
- var wwwnewsite = "www.".concat(newsite) // Add www. to newsite for another url var
- if (siteSchemes[newsite]) { // Locate scheme if main domain doesn't use www
- scheme = siteSchemes[newsite];
- }
- else if (siteSchemes[wwwnewsite]) { // Locate scheme if main domain uses www
- scheme = siteSchemes[wwwnewsite];
- }
- }
- if (!(scheme)) { // Rest of the function handles the situation where
- scheme = getDefaultScheme(); // there is no rule for the actual url or the url
- } // adjusted one domain up.
- } catch (e) {
- scheme = getDefaultScheme();
- }
- return scheme;
- }
- function setSiteScheme(site, scheme) {
- if (!(scheme)) {
- scheme = getDefaultScheme();
- }
- var siteSchemes = {};
- try {
- siteSchemes = JSON.parse(localStorage['siteschemes']);
- siteSchemes['www.example.com'] = getDefaultScheme();
- } catch (e) {
- siteSchemes = {};
- }
- siteSchemes[site] = scheme;
- localStorage['siteschemes'] = JSON.stringify(siteSchemes);
- }
- function resetSiteSchemes() {
- var siteSchemes = {};
- localStorage['siteschemes'] = JSON.stringify(siteSchemes);
- }
- function siteFromUrl(url) {
- var a = document.createElement('a');
- a.href = url;
- return a.hostname;
- }
- function getModifiers() {
- var modifiers = '';
- if (isLowContrast()) {
- modifiers = 'low-contrast';
- }
- return modifiers;
- }
- function isLowContrast() {
- var result = localStorage['low_contrast'];
- if (result === 'true' || result === 'false') {
- return (result === 'true');
- }
- localStorage['low_contrast'] = 'false';
- return false;
- }
- function isDisallowedUrl(url) {
- return url.indexOf('chrome') == 0 || url.indexOf('about') == 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement