1212// @grant GM_notification
1313// @grant GM_openInTab
1414// @grant GM_xmlhttpRequest
15+ // @grant GM_setValue
16+ // @grant GM_getValue
1517// @connect *
1618// @noframes
1719// @require https://cdn.rawgit.com/coolaj86/TextEncoderLite/v1.0.0/index.js
1820// @require https://cdn.rawgit.com/beatgammit/base64-js/v1.1.2/base64js.min.js
1921// @downloadURL https://raw.githubusercontent.com/AlorelUserscripts/data-url-generator/master/data-url.user.js
2022// @updateURL https://raw.githubusercontent.com/AlorelUserscripts/data-url-generator/master/data-url.meta.js
21- // @icon https://cdn.rawgit.com/AlorelUserscripts/data-url-generator/0.1/ico.png
23+
24+ // @icon https://cdn.rawgit.com/AlorelUserscripts/data-url-generator/develop/assets/ico.png
2225// @license LGPL-2.1
2326// ==/UserScript==
2427
110113
111114 for ( ; i < pageElements . length ; i ++ ) {
112115 if ( pageElements [ i ] instanceof HTMLImageElement ) {
113- ret . push ( pageElements [ i ] . src ) ;
116+ ret . push ( {
117+ url : pageElements [ i ] . src ,
118+ element : pageElements [ i ]
119+ } ) ;
114120 } else {
115121 for ( j = 0 ; j < pseudos . length ; j ++ ) {
116122 if (
117123 ( bgImg = getComputedStyle ( pageElements [ i ] , pseudos [ j ] ) . backgroundImage ) !== BG_IMG_NONE &&
118124 ( bgImg = bgImg . match ( bgImgRegex ) )
119125 ) {
120126 for ( k = 0 ; k < bgImg . length ; k ++ ) {
121- ret . push ( bgImg [ k ] . replace ( bgImgRegex , "$1" ) ) ;
127+ ret . push ( {
128+ url : bgImg [ k ] . replace ( bgImgRegex , "$1" ) ,
129+ element : pageElements [ i ]
130+ } ) ;
122131 }
123132 }
124133 }
125134 }
126135 }
127136
128137 //Begin generating our DOM
129- var html = document . createElement ( "html" ) ,
130- head = document . createElement ( "head" )
138+ var body = document . createElement ( "body" ) ,
139+ table = document . createElement ( "table" ) ,
140+ thead = document . createElement ( "thead" ) ,
141+ tfoot = document . createElement ( "tfoot" ) ,
142+ tbody = document . createElement ( "tbody" ) ,
143+ tr , preview , selector ;
144+
145+ table . style . width = "100%" ;
146+ table . style . borderCollapse = "collapse" ;
147+ thead . innerHTML = '<tr>\
148+ <th style="border:1px solid black">Preview</th>\
149+ <th style="border:1px solid black">Rough selector</th>\
150+ </tr>' ;
151+ tfoot . innerHTML = thead . innerHTML ;
152+
153+ ret . forEach ( function ( r ) {
154+ tr = document . createElement ( "tr" ) ;
155+ preview = document . createElement ( "td" ) ;
156+ selector = document . createElement ( "td" ) ;
157+
158+ selector . style . whiteSpace = "nowrap" ;
159+ tr . style . border = preview . style . border = selector . style . border = "1px solid black" ;
160+
161+ preview . innerHTML = '<img src="' + r . url + '" style="max-width:100%;height:auto"/>' ;
162+ selector . innerText = 'To be implemented' ;
163+
164+ tr . appendChild ( preview ) ;
165+ tr . appendChild ( selector ) ;
166+ tbody . appendChild ( tr ) ;
167+ } ) ;
168+
169+ table . appendChild ( thead ) ;
170+ table . appendChild ( tbody ) ;
171+ table . appendChild ( tfoot ) ;
172+ body . appendChild ( table ) ;
173+
174+ var a = document . createElement ( "a" ) ,
175+ event = document . createEvent ( 'HTMLEvents' ) ;
176+ event . initEvent ( 'click' , true , false ) ;
177+ a . href = "data:text/html;base64," + base64js . fromByteArray ( encoder . encode ( body . outerHTML ) ) ;
178+ a . target = "_blank" ;
179+ a . style . display = "none" ;
180+ document . body . appendChild ( a ) ;
181+ a . dispatchEvent ( event ) ;
182+ a . parentNode . removeChild ( a ) ;
131183 } , "s" ) ;
132184 }
133185} ) ( GM_notification ) ;
0 commit comments