Reddit RES Style Class

Adds class to html for subreddit RES style on/off

目前为 2016-04-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit RES Style Class
  3. // @namespace http://your.homepage/
  4. // @version 1.0
  5. // @description Adds class to html for subreddit RES style on/off
  6. // @author muffleyd
  7. // @match http*://*.reddit.com/r/*
  8. // @grant none
  9. // @run-at document-body
  10. // ==/UserScript==
  11.  
  12. var classname = 'no-subr-style'
  13. var classname2 = 'yes-subr-style'
  14. var $html = $('html')
  15. $html.addClass(classname2)
  16.  
  17. window.addEventListener ("load", function () {
  18.  
  19. var toggleStyle = function () {
  20. $html.removeClass(classname).removeClass(classname2)
  21. if ($('head link[title="applied_subreddit_stylesheet"]').length == 0) {
  22. $html.addClass(classname)
  23. } else {
  24. $html.addClass(classname2)
  25. }
  26. /*if ($el.length) {
  27. if (!$el[0].checked) {
  28. $html.addClass(classname)
  29. } else {
  30. $html.addClass(classname2)
  31. }
  32. }*/
  33. }
  34.  
  35. var $el = $('')
  36. var refresh$el = function () {
  37. $el.off('click', toggleStyle)
  38. $el = $('.res-sr-style-toggle > input[type=checkbox]')
  39. if ($el.length) {
  40. $el.on('change', toggleStyle)
  41. }
  42. }
  43.  
  44. document.addEventListener('visibilitychange', function () {
  45. if (!document.hidden) {
  46. refresh$el()
  47. toggleStyle()
  48. }
  49. })
  50.  
  51. refresh$el()
  52. toggleStyle()
  53.  
  54. })