Advertisement
soldier9599

common.js for Deluminate (Chrome extension)

Apr 28th, 2014
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This is an edited version of the common.js file from
  3. Deluminate 0.3.2_0, the Google Chrome extension. The
  4. changes that I made are exclusively in the function:
  5. getSiteScheme(). The purpose of these changes are to
  6. make it so that any rules set for a domain carry over
  7. to all subdomains, unless a rule is already set for
  8. that specific subdomain. You can still create rules
  9. for subdomains and they will be remembered as such
  10. without affecting the rules for any other subdomains.
  11. I added conditionals specifically to handle any website
  12. regardless of whether or not the primary domain is
  13. accessed starting with "www."
  14.  
  15. In my testing, the GUI works as expected for those
  16. rule defining characteristics without needing to make
  17. any other alterations to any parts of Deluminate. I
  18. have not had anyone else test this yet, so if you see
  19. any issues or have any questions, feel free to contact
  20. me at soldier9599@gmail.com
  21. */
  22.  
  23. var DEFAULT_SCHEME = "delumine-smart";
  24.  
  25. function $(id) {
  26.   return document.getElementById(id);
  27. }
  28.  
  29. function getEnabled() {
  30.   var result = localStorage['enabled'];
  31.   if (result === 'true' || result === 'false') {
  32.     return (result === 'true');
  33.   }
  34.   localStorage['enabled'] = 'true';
  35.   return true;
  36. }
  37.  
  38. function setEnabled(enabled) {
  39.   localStorage['enabled'] = enabled;
  40. }
  41.  
  42. function getKeyAction() {
  43.   var keyAction = localStorage['keyaction'];
  44.   if (keyAction == 'global' || keyAction == 'site') {
  45.     return keyAction;
  46.   }
  47.   keyAction = 'global';
  48.   localStorage['keyaction'] = keyAction;
  49.   return keyAction;
  50. }
  51.  
  52. function setKeyAction(keyAction) {
  53.   if (keyAction != 'global' && keyAction != 'site') {
  54.     keyAction = 'global';
  55.   }
  56.   localStorage['keyaction'] = keyAction;
  57. }
  58.  
  59. function getDefaultScheme() {
  60.   var scheme = localStorage['scheme'];
  61.   if (scheme) {
  62.     return scheme;
  63.   }
  64.   scheme = DEFAULT_SCHEME;
  65.   localStorage['scheme'] = scheme;
  66.   return scheme;
  67. }
  68.  
  69. function setDefaultScheme(scheme) {
  70.   if (!(scheme)) {
  71.     scheme = DEFAULT_SCHEME;
  72.   }
  73.   localStorage['scheme'] = scheme;
  74. }
  75.  
  76. function getSiteScheme(site) {
  77.   var scheme = getDefaultScheme();
  78.   try {
  79.     var siteSchemes = JSON.parse(localStorage['siteschemes']);
  80.     if (siteSchemes[site]) {                // If it already matches a rule, follow it.
  81.       scheme = siteSchemes[site]
  82.     }
  83.     else if (site.indexOf("www") == -1) {           // If not a www and has no specific rule
  84.       var newsite = site.substr(site.indexOf(".") + 1)  // Remove lowest level domain for new url var
  85.       var wwwnewsite = "www.".concat(newsite)       // Add www. to newsite for another url var
  86.       if (siteSchemes[newsite]) {               // Locate scheme if main domain doesn't use www
  87.         scheme = siteSchemes[newsite];
  88.       }
  89.       else if (siteSchemes[wwwnewsite]) {           // Locate scheme if main domain uses www
  90.         scheme = siteSchemes[wwwnewsite];
  91.       }
  92.     }
  93.     if (!(scheme)) {                        // Rest of the function handles the situation where
  94.       scheme = getDefaultScheme();              // there is no rule for the actual url or the url
  95.     }                               // adjusted one domain up.
  96.   } catch (e) {
  97.     scheme = getDefaultScheme();
  98.   }
  99.   return scheme;
  100. }
  101.  
  102.  
  103. function setSiteScheme(site, scheme) {
  104.   if (!(scheme)) {
  105.     scheme = getDefaultScheme();
  106.   }
  107.   var siteSchemes = {};
  108.   try {
  109.     siteSchemes = JSON.parse(localStorage['siteschemes']);
  110.     siteSchemes['www.example.com'] = getDefaultScheme();
  111.   } catch (e) {
  112.     siteSchemes = {};
  113.   }
  114.   siteSchemes[site] = scheme;
  115.   localStorage['siteschemes'] = JSON.stringify(siteSchemes);
  116. }
  117.  
  118. function resetSiteSchemes() {
  119.   var siteSchemes = {};
  120.   localStorage['siteschemes'] = JSON.stringify(siteSchemes);
  121. }
  122.  
  123. function siteFromUrl(url) {
  124.   var a = document.createElement('a');
  125.   a.href = url;
  126.   return a.hostname;
  127. }
  128.  
  129. function getModifiers() {
  130.   var modifiers = '';
  131.   if (isLowContrast()) {
  132.     modifiers = 'low-contrast';
  133.   }
  134.   return modifiers;
  135. }
  136.  
  137. function isLowContrast() {
  138.   var result = localStorage['low_contrast'];
  139.  
  140.   if (result === 'true' || result === 'false') {
  141.     return (result === 'true');
  142.   }
  143.   localStorage['low_contrast'] = 'false';
  144.   return false;
  145. }
  146.  
  147. function isDisallowedUrl(url) {
  148.   return url.indexOf('chrome') == 0 || url.indexOf('about') == 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement