InstaSynchP CSSLoader

Plugin to load and unload CSS urls

目前为 2015-02-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name InstaSynchP CSSLoader
  3. // @namespace InstaSynchP
  4. // @description Plugin to load and unload CSS urls
  5.  
  6. // @version 1.0.5
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-CSSLoader
  9. // @license MIT
  10.  
  11. // @include *://instasync.com/r/*
  12. // @include *://*.instasync.com/r/*
  13. // @grant none
  14. // @run-at document-start
  15.  
  16. // @require https://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=37716
  17. // ==/UserScript==
  18.  
  19. function CSSLoader(version) {
  20. "use strict";
  21. this.version = version;
  22. this.name = 'InstaSynchP CSSLoader';
  23. this.styles = {};
  24. }
  25.  
  26. CSSLoader.prototype.executeOnceCore = function () {
  27. "use strict";
  28. var th = this;
  29. window.cssLoader = (function () {
  30.  
  31. return {
  32. 'add': function (style) {
  33. //set the id as the name if it didn't get set
  34. if (!style.id) {
  35. style.id = style.name;
  36. }
  37.  
  38. //save the style
  39. th.styles[style.name] = style;
  40.  
  41. //load it
  42. if (style.autoload) {
  43. cssLoader.load(style.name);
  44. }
  45. },
  46. 'load': function (styleName) {
  47. var style = th.styles[styleName],
  48. id = '#{0}'.format(style.id);
  49. $(id).remove();
  50.  
  51. $('head').append(
  52. $('<link>', {
  53. 'rel': 'stylesheet',
  54. 'type': 'text/css',
  55. 'id': style.id,
  56. 'href': style.url
  57. }).on('load', function () {
  58. var ref = this;
  59. //fire event after the CSS has been loaded
  60. setTimeout(function () {
  61. events.fire('CSSLoad[{0}]'.format($(ref).attr('id')));
  62. }, 1000);
  63. })
  64. );
  65. //if the is nothing to load fire the event directly
  66. if (style.url === '') {
  67. events.fire('CSSLoad[{0}]'.format(style.id));
  68. }
  69. }
  70. };
  71. }());
  72. };
  73.  
  74. window.plugins = window.plugins || {};
  75. window.plugins.cssLoader = new CSSLoader('1.0.5');