InstaSynchP CSSLoader

Plugin to load and unload CSS urls

目前为 2014-10-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name InstaSynchP CSSLoader
  3. // @namespace InstaSynchP
  4. // @description Plugin to load and unload CSS urls
  5.  
  6. // @version 1
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-CSSLoader
  9. // @license GPL-3.0
  10.  
  11. // @include http://*.instasynch.com/*
  12. // @include http://instasynch.com/*
  13. // @include http://*.instasync.com/*
  14. // @include http://instasync.com/*
  15. // @grant none
  16. // @run-at document-start
  17.  
  18. // @require https://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js
  19. // ==/UserScript==
  20.  
  21. function CSSLoader(version) {
  22. "use strict";
  23. this.version = version;
  24. }
  25.  
  26. CSSLoader.prototype.executeOnceCore = function() {
  27. "use strict";
  28. window.cssLoader = (function () {
  29. var styles = {};
  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. 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 = 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. //fire event after the CSS has been loaded
  59. events.fire('onCSSLoad[{0}]'.format($(this).attr('id')));
  60. })
  61. );
  62. //if the is nothing to load fire the event directly
  63. if (style.url === '') {
  64. events.fire('onCSSLoad[{0}]'.format(style.id));
  65. }
  66. }
  67. };
  68. }());
  69. };
  70.  
  71. window.plugins = window.plugins || {};
  72. window.plugins.cssLoader = new CSSLoader("1");