Advertisement
Coriic

Untitled

Jan 18th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var sheets = document.querySelectorAll('[rel="alternate stylesheet"]');
  2.  
  3. window.onload = function(e){
  4.     for(var i=0; i<sheets.length; i++){
  5.         if(document.cookie.split(";")[0].split("=")[1] == sheets[i].title){
  6.             sheets[i].disabled = false;
  7.         }
  8.         else{
  9.             sheets[i].disabled = true;
  10.         }
  11.     }
  12. }
  13.  
  14. function changeStyle(obj){
  15.     for(var i=0; i<sheets.length; i++){
  16.         if(sheets[i].title == obj){
  17.             sheets[i].disabled = false;
  18.             document.cookie = "title="+sheets[i].title+";";
  19.         }
  20.         else{
  21.             sheets[i].disabled = true;
  22.         }
  23.     }
  24. }
  25.  
  26. var container = document.getElementById("stylesheets");
  27. var ul= document.createElement("ul");
  28. for (var i=0; i<sheets.length; i++){
  29.     var li = document.createElement("li");
  30.     var a = document.createElement("a");
  31.     a.title = sheets[i].title;
  32.     a.innerHTML = sheets[i].title;
  33.     a.href="#";
  34.     a.setAttribute('onclick', "changeStyle(this.title); event.preventDefault();");
  35.     li.appendChild(a);
  36.     ul.appendChild(li);
  37. }
  38. container.appendChild(ul);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement