Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. StyleSheetList.prototype.reload_interval = 1000; // 1 second
  2.  
  3. CSSStyleSheet.prototype.reload = function reload(){
  4. // Reload one stylesheet
  5. // usage: document.styleSheets[0].reload()
  6. // return: URI of stylesheet if it could be reloaded, overwise undefined
  7. if (this.href) {
  8. var href = this.href;
  9. var i = href.indexOf('?'),
  10. last_reload = 'last_reload=' + (new Date).getTime();
  11. if (i < 0) {
  12. href += '?' + last_reload;
  13. } else if (href.indexOf('last_reload=', i) < 0) {
  14. href += '&' + last_reload;
  15. } else {
  16. href = href.replace(/last_reload=\d+/, last_reload);
  17. }
  18. return this.ownerNode.href = href;
  19. }
  20. };
  21.  
  22. StyleSheetList.prototype.reload = function reload(){
  23. // Reload all stylesheets
  24. // usage: document.styleSheets.reload()
  25. for (var i=0; i<this.length; i++) {
  26. this[i].reload()
  27. }
  28. };
  29.  
  30. StyleSheetList.prototype.start_autoreload = function start_autoreload(miliseconds /*Number*/){
  31. // usage: document.styleSheets.start_autoreload()
  32. if (!start_autoreload.running) {
  33. var styles = this;
  34. start_autoreload.running = setInterval(function reloading(){
  35. styles.reload();
  36. }, miliseconds || this.reload_interval);
  37. }
  38. return start_autoreload.running;
  39. };
  40.  
  41. StyleSheetList.prototype.stop_autoreload = function stop_autoreload(){
  42. // usage: document.styleSheets.stop_autoreload()
  43. clearInterval(this.start_autoreload.running);
  44. this.start_autoreload.running = null;
  45. };
  46.  
  47. StyleSheetList.prototype.toggle_autoreload = function toggle_autoreload(){
  48. // usage: document.styleSheets.toggle_autoreload()
  49. return this.start_autoreload.running ? this.stop_autoreload() : this.start_autoreload();
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement