JAVASCRIPT   33

set ActiveStyle Sheet

Guest on 28th June 2022 04:35:57 AM

  1. function setActiveStyleSheet(title) {
  2.  
  3.   var i, a, main;
  4.  
  5.   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  6.  
  7.     if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
  8.  
  9.       a.disabled = true;
  10.  
  11.       if(a.getAttribute("title") == title) a.disabled = false;
  12.  
  13.     }
  14.  
  15.   }
  16.  
  17. }
  18.  
  19.  
  20.  
  21. function getActiveStyleSheet() {
  22.  
  23.   var i, a;
  24.  
  25.   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  26.  
  27.     if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  28.  
  29.   }
  30.  
  31.   return null;
  32.  
  33. }
  34.  
  35.  
  36.  
  37. function getPreferredStyleSheet() {
  38.  
  39.   var i, a;
  40.  
  41.   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  42.  
  43.     if(a.getAttribute("rel").indexOf("style") != -1
  44.  
  45.        && a.getAttribute("rel").indexOf("alt") == -1
  46.  
  47.        && a.getAttribute("title")
  48.  
  49.        ) return a.getAttribute("title");
  50.  
  51.   }
  52.  
  53.   return null;
  54.  
  55. }
  56.  
  57.  
  58.  
  59. function createCookie(name,value,days) {
  60.  
  61.   if (days) {
  62.  
  63.     var date = new Date();
  64.  
  65.     date.setTime(date.getTime()+(days*24*60*60*1000));
  66.  
  67.     var expires = "; expires="+date.toGMTString();
  68.  
  69.   }
  70.  
  71.   else expires = "";
  72.  
  73.   document.cookie = name+"="+value+expires+"; path=/";
  74.  
  75. }
  76.  
  77.  
  78.  
  79. function readCookie(name) {
  80.  
  81.   var nameEQ = name + "=";
  82.  
  83.   var ca = document.cookie.split(';');
  84.  
  85.   for(var i=0;i < ca.length;i++) {
  86.  
  87.     var c = ca[i];
  88.  
  89.     while (c.charAt(0)==' ') c = c.substring(1,c.length);
  90.  
  91.     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  92.  
  93.   }
  94.  
  95.   return null;
  96.  
  97. }
  98.  
  99.  
  100.  
  101. window.onload = function(e) {
  102.  
  103.   var cookie = readCookie("style");
  104.  
  105.   var title = cookie ? cookie : getPreferredStyleSheet();
  106.  
  107.   setActiveStyleSheet(title);
  108.  
  109. }
  110.  
  111.  
  112.  
  113. window.onunload = function(e) {
  114.  
  115.   var title = getActiveStyleSheet();
  116.  
  117.   createCookie("style", title, 365);
  118.  
  119. }
  120.  
  121.  
  122.  
  123. var cookie = readCookie("style");
  124.  
  125. var title = cookie ? cookie : getPreferredStyleSheet();
  126.  
  127. setActiveStyleSheet(title);
  128.  
  129.  
  130.  
  131.  
  132. *window.oncontextmenu=function(){
  133.  
  134. return false;
  135.  
  136. }
  137.  
  138.  
  139.  
  140. document.oncontextmenu=function(){
  141.  
  142. return false;
  143.  
  144. }

Raw Paste


Login or Register to edit or fork this paste. It's free.