1+ // ==UserScript==
2+ // @name Userscript+ : Show Site All UserJS
3+ // @name :zh Userscript+ : 显示当前网站所有可用的UserJS脚本 Jaeger
4+ // @name :zh-CN Userscript+ : 显示当前网站所有可用的UserJS脚本 Jaeger
5+ // @namespace https://github.com/jae-jae/Userscript-Plus
6+ // @version 2.1.2
7+ // @description Show current site all UserJS,The easier way to install UserJs for Tampermonkey.
8+ // @description :zh 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
9+ // @description :zh-CN 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
10+ // @author Jaeger <[email protected] > 11+ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3ggEBCQHM3fXsAAAAVdJREFUOMudkz2qwkAUhc/goBaGJBgUtBCZyj0ILkpwAW7Bws4yO3AHLiCtEFD8KVREkoiFxZzX5A2KGfN4F04zMN+ce+5c4LMUgDmANYBnrnV+plBSi+FwyHq9TgA2LQpvCiEiABwMBtzv95RSfoNEHy8DYBzHrNVqVEr9BWKcqNFoxF6vx3a7zc1mYyC73a4MogBg7vs+z+czO50OW60Wt9stK5UKp9Mpj8cjq9WqDTBHnjAdxzGQZrPJw+HA31oulzbAWgLoA0CWZVBKIY5jzGYzdLtdE9DlcrFNrY98zobqOA6TJKHW2jg4nU5sNBpFDp6mhVe5rsvVasUwDHm9Xqm15u12o+/7Hy0gD8KatOd5vN/v1FozTVN6nkchxFuI6hsAAIMg4OPxMJCXdtTbR7JJCMEgCJhlGUlyPB4XfumozInrupxMJpRSRtZlKoNYl+m/6/wDuWAjtPfsQuwAAAAASUVORK5CYII=
12+ // @include *
13+ // @exclude http://www.dev/Show-Site-All-UserJS/ui.html
14+ // @require https://greasyfork.org/scripts/23419-l-js/code/ljs.js?version=148792
15+ // @require https://greasyfork.org/scripts/23420-userjs-base-js/code/userjs-basejs.js?version=214700
16+ // @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_=1505668754554
17+ // @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1505668754554
18+ // @grant GM_xmlhttpRequest
19+ // @grant GM_getResourceText
20+ // @grant GM_getValue
21+ // @grant GM_setValue
22+ // @noframes
23+ // @connect cdn.bootcss.com
24+ // @connect raw.githubusercontent.com
25+ // @connect gist.githubusercontent.com
26+ // @connect greasyfork.org
27+ // @run -at document-end
28+ // ==/UserScript==
29+
30+
31+ ( function ( ) {
32+
33+ 'use strict' ;
34+
35+ var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
36+
37+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
38+
39+ var FetchUserjs = function ( ) {
40+ function FetchUserjs ( ) {
41+ _classCallCheck ( this , FetchUserjs ) ;
42+
43+ this . homeUrl = 'https://greasyfork.org/zh-CN/scripts/24508' ;
44+ this . api = 'https://greasyfork.org/en/scripts/by-site/{host}.json' ;
45+ this . host = location . host . split ( '.' ) . splice ( - 2 ) . join ( '.' ) ;
46+ this . showTime = 10 ;
47+ this . quietKey = 'jae_fetch_userjs_quiet' ;
48+ this . cacheKey = 'jae_fetch_userjs_cache' ;
49+ this . tplBox = '<div id="jae_userscript_box"><style>.jae-userscript{position:fixed;width:370px;bottom:10px;right:20px;z-index:9999999999;height:56px}.jae-userscript-shadow{box-shadow:0 1px 4px rgba(0,0,0,.3),\\t\\t\\t\\t0px 0 20px rgba(0,0,0,.1) inset}.jae-userscript-shadow::before,.jae-userscript-shadow::after{content:"";position:absolute;z-index:-1}.jae-userscript-shadow::before,.jae-userscript-shadow::after{content:"";position:absolute;z-index:-1;bottom:15px;left:10px;width:50%;height:20%}.jae-userscript-shadow::before,.jae-userscript-shadow::after{content:"";position:absolute;z-index:-1;bottom:15px;left:10px;width:50%;height:20%;box-shadow:0 15px 10px rgba(0,0,0,.7);transform:rotate(-3deg)}.jae-userscript-shadow::after{right:10px;left:auto;transform:rotate(3deg)}</style><div class="jae-userscript" class=""></div></div>' ;
50+ }
51+
52+ /* Nano Templates - https://github.com/trix/nano */
53+
54+
55+ _createClass ( FetchUserjs , [ {
56+ key : 'nano' ,
57+ value : function nano ( template , data ) {
58+ return template . replace ( / \{ ( [ \w \. ] * ) \} / g, function ( str , key ) {
59+ var keys = key . split ( "." ) ,
60+ v = data [ keys . shift ( ) ] ;
61+ for ( var i = 0 , l = keys . length ; i < l ; i ++ ) {
62+ v = v [ keys [ i ] ] ;
63+ } return typeof v !== "undefined" && v !== null ? v : "" ;
64+ } ) ;
65+ }
66+ } , {
67+ key : 'getJSON' ,
68+ value : function getJSON ( url , callback ) {
69+ GM_xmlhttpRequest ( {
70+ method : 'GET' ,
71+ url : url ,
72+ onload : function onload ( res ) {
73+ var json = JSON . parse ( res . responseText ) ;
74+ callback ( json ) ;
75+ }
76+ } ) ;
77+ }
78+ } , {
79+ key : 'getData' ,
80+ value : function getData ( host , callback ) {
81+ var _this = this ;
82+
83+ var data = sessionStorage . getItem ( this . cacheKey ) ;
84+ if ( data ) {
85+ data = JSON . parse ( data ) ;
86+ callback ( data ) ;
87+ } else {
88+ var api = this . nano ( this . api , {
89+ host : this . host
90+ } ) ;
91+ this . getJSON ( api , function ( json ) {
92+ sessionStorage . setItem ( _this . cacheKey , JSON . stringify ( json ) ) ;
93+ callback ( json ) ;
94+ } ) ;
95+ }
96+ }
97+ } , {
98+ key : 'setSize' ,
99+ value : function setSize ( w , h ) {
100+ $ ( '.jae-userscript' ) . css ( {
101+ width : w ,
102+ height : h
103+ } ) ;
104+ }
105+ } , {
106+ key : 'addEventListener' ,
107+ value : function addEventListener ( eventName , handler ) {
108+ document . getElementById ( 'jae_userscript_box' ) . addEventListener ( eventName , handler ) ;
109+ }
110+ } , {
111+ key : 'bindEvent' ,
112+ value : function bindEvent ( ) {
113+ var _this2 = this ;
114+
115+ this . timeId = setTimeout ( function ( ) {
116+ $ ( '#jae_userscript_box' ) . remove ( ) ;
117+ } , this . showTime * 1000 ) ;
118+
119+ this . addEventListener ( 'max' , function ( ) {
120+ _this2 . setSize ( 860 , 492 ) ;
121+ $ ( '.jae-userscript' ) . addClass ( 'jae-userscript-shadow' ) ;
122+ clearTimeout ( _this2 . timeId ) ;
123+ } ) ;
124+
125+ this . addEventListener ( 'min' , function ( ) {
126+ setTimeout ( function ( ) {
127+ $ ( '.jae-userscript' ) . removeClass ( 'jae-userscript-shadow' ) ;
128+ _this2 . setSize ( 370 , 56 ) ;
129+ } , 500 ) ;
130+ } ) ;
131+
132+ this . addEventListener ( 'close' , function ( ) {
133+ sessionStorage . setItem ( _this2 . quietKey , 1 ) ;
134+ $ ( '#jae_userscript_box' ) . remove ( ) ;
135+ } ) ;
136+ }
137+ } , {
138+ key : 'execFrameJs' ,
139+ value : function execFrameJs ( frameWindow ) {
140+ var uiJs = GM_getResourceText ( 'uiJs' ) ;
141+ return function ( jsStr ) {
142+ frameWindow . eval ( jsStr ) ;
143+ } . call ( frameWindow , uiJs ) ;
144+ }
145+ } , {
146+ key : 'render' ,
147+ value : function render ( ) {
148+ var _this3 = this ;
149+
150+ this . isQuiet || this . getData ( this . host , function ( json ) {
151+ if ( json . length ) {
152+
153+ $ ( 'body' ) . append ( _this3 . tplBox ) ;
154+
155+ var ui = GM_getResourceText ( 'ui' ) ;
156+ var dom = document . getElementsByClassName ( 'jae-userscript' ) [ 0 ] ;
157+ var tpl = '<iframe name="jaeFetchUserJSFrame" src="about:blank" style="width:100%;height:100%;border:0px;display: block!important;" allowTransparency="true"></iframe>' ;
158+ dom . innerHTML = tpl ;
159+ var iframeDom = dom . children [ 0 ] ;
160+ iframe . write ( iframeDom , ui ) ;
161+
162+ _this3 . execFrameJs ( jaeFetchUserJSFrame . window ) ;
163+
164+ _this3 . bindEvent ( ) ;
165+ }
166+ } ) ;
167+ }
168+ } , {
169+ key : 'isQuiet' ,
170+ get : function get ( ) {
171+ var quiet = sessionStorage . getItem ( this . quietKey ) ;
172+ return quiet ? true : false ;
173+ }
174+ } ] ) ;
175+
176+ return FetchUserjs ;
177+ } ( ) ;
178+
179+ ljs . exec ( [ 'jQuery' , 'iframe' ] , function ( ) {
180+ var fu = new FetchUserjs ( ) ;
181+ fu . render ( ) ;
182+ } ) ;
183+
184+ } ) ( ) ;
0 commit comments