|
10 | 10 | debugging: GM_getValue('SOX-debug', false) |
11 | 11 | }; |
12 | 12 |
|
| 13 | + sox.NEW_TOPBAR = location.href.indexOf('area51') === -1; |
| 14 | + |
13 | 15 | sox.debug = function() { |
14 | | - if(!sox.info.debugging) return; |
| 16 | + if (!sox.info.debugging) return; |
15 | 17 | for (var arg = 0; arg < arguments.length; ++arg) { |
16 | 18 | console.debug('SOX: ', arguments[arg]); |
17 | 19 | } |
|
42 | 44 | }; |
43 | 45 |
|
44 | 46 | //var Stack = (typeof StackExchange === "undefined" ? window.eval('if (typeof StackExchange != "undefined") StackExchange') : StackExchange) | undefined; |
45 | | - var Chat = (typeof CHAT === "undefined" ? window.eval("typeof CHAT != 'undefined' ? CHAT : undefined") : CHAT); |
46 | | - sox.debug(Chat); |
47 | | - var Stack = (typeof Chat === "undefined" ? (typeof StackExchange === "undefined" ? window.eval('if (typeof StackExchange != "undefined") StackExchange') : StackExchange) : undefined); |
48 | | - sox.debug(Stack); |
| 47 | + var Chat, Stack; |
| 48 | + if (location.href.indexOf('github.com') === -1) { //need this so it works on FF -- CSP blocks window.eval() it seems |
| 49 | + Chat = (typeof CHAT === "undefined" ? window.eval("typeof CHAT != 'undefined' ? CHAT : undefined") : CHAT); |
| 50 | + sox.debug(Chat); |
| 51 | + Stack = (typeof Chat === "undefined" ? (typeof StackExchange === "undefined" ? window.eval('if (typeof StackExchange != "undefined") StackExchange') : StackExchange) : undefined); |
| 52 | + sox.debug(Stack); |
| 53 | + } |
| 54 | + |
| 55 | + sox.Stack = Stack; |
49 | 56 |
|
50 | 57 | sox.exists = function(path) { |
51 | | - if(!Stack) return false; |
| 58 | + if (!Stack) return false; |
52 | 59 | var toCheck = path.split('.'), |
53 | 60 | cont = true, |
54 | 61 | o = Stack, |
|
101 | 108 | var keys = GM_listValues(); |
102 | 109 | for (var i = 0; i < keys.length; i++) { |
103 | 110 | var key = keys[i]; |
104 | | - if(hideAccessToken && key == 'SOX-accessToken') { |
| 111 | + if (hideAccessToken && key == 'SOX-accessToken') { |
105 | 112 | sox.loginfo('access token set'); |
106 | 113 | } else { |
107 | 114 | sox.loginfo(key, GM_getValue(key)); |
|
120 | 127 | success: function(d) { |
121 | 128 | if (d.backoff) { |
122 | 129 | sox.error('SOX Error: BACKOFF: ' + d.backoff); |
| 130 | + } else if (d.error_id == 502) { |
| 131 | + sox.error('THROTTLE VIOLATION', d); |
| 132 | + } else if (d.error_id == 403) { |
| 133 | + sox.warn('Access token invalid! Opening window to get new one'); |
| 134 | + window.open('https://stackexchange.com/oauth/dialog?client_id=7138&scope=no_expiry&redirect_uri=http://soscripted.github.io/sox/'); |
| 135 | + alert('Your access token is no longer valid. A window has been opened to request a new one.'); |
123 | 136 | } else { |
124 | 137 | callback(d); |
125 | 138 | } |
|
131 | 144 | }, |
132 | 145 | observe: function(elements, callback, toObserve) { |
133 | 146 | sox.debug('observe: ' + elements); |
134 | | - sox.debug(toObserve); |
135 | 147 | var observer = new MutationObserver(function(mutations, observer) { |
136 | 148 | for (var i = 0; i < mutations.length; i++) { |
137 | | - for (var a = 0; a < mutations[i].addedNodes.length; a++) { |
138 | | - var $a = $(mutations[i].addedNodes[a]); |
139 | | - if ($a && $a.is((Array.isArray(elements) ? elements.join(',') : elements))) { |
140 | | - callback(mutations[i].addedNodes[a]); |
141 | | - sox.debug('fire (added): ' + elements); |
142 | | - } |
143 | | - } |
144 | | - for (var r = 0; r < mutations[i].removedNodes.length; r++) { |
145 | | - var $r = $(mutations[i].removedNodes[r]); |
146 | | - if ($r && $r.is((Array.isArray(elements) ? elements.join(',') : elements))) { |
147 | | - callback(mutations[i].addedNodes[r]); |
148 | | - sox.debug('fire (removed): ' + elements); |
149 | | - } |
| 149 | + //sox.debug($(mutations[i].target)); |
| 150 | + if ($(mutations[i].target).is(elements)) { |
| 151 | + callback(mutations[i].target); |
| 152 | + sox.debug('fire: target: ', mutations[i].target); |
| 153 | + return; |
150 | 154 | } |
151 | 155 | } |
152 | 156 | }); |
|
234 | 238 | apiParameter: function(siteName) { |
235 | 239 | if (commonInfo.apiParameters.hasOwnProperty(siteName)) { |
236 | 240 | return commonInfo.apiParameters[siteName]; |
237 | | - } else if(sox.location.on('area51')) { |
| 241 | + } else if (sox.location.on('area51')) { |
238 | 242 | return 'area51'; |
239 | 243 | } |
240 | 244 | }, |
|
244 | 248 | } |
245 | 249 | }, |
246 | 250 | get currentApiParameter() { |
247 | | - return this.apiParameter(this.name); |
| 251 | + return this.apiParameter(this.name || (location.href.indexOf('stackapps.com/') > -1 ? "Stack Apps" : undefined)); |
248 | 252 | }, |
249 | 253 | get icon() { |
250 | 254 | return "favicon-" + $(".current-site a:not([href*='meta']) .site-icon").attr('class').split('favicon-')[1]; |
|
265 | 269 | return this.on('/questions/'); |
266 | 270 | }, |
267 | 271 | matchWithPattern: function(pattern, urlToMatchWith) { //commented version @ https://jsfiddle.net/shub01/t90kx2dv/ |
268 | | - if(pattern == 'SE1.0') { //SE.com && Area51.SE.com special checking |
269 | | - if(urlToMatchWith) { |
270 | | - if(urlToMatchWith.match(/https?:\/\/stackexchange\.com\/?/) || sox.location.matchWithPattern('*://area51.stackexchange.com/*')) return true; |
| 272 | + if (pattern == 'SE1.0') { //SE.com && Area51.SE.com special checking |
| 273 | + if (urlToMatchWith) { |
| 274 | + if (urlToMatchWith.match(/https?:\/\/stackexchange\.com\/?/) || sox.location.matchWithPattern('*://area51.stackexchange.com/*')) return true; |
271 | 275 | } else { |
272 | | - if(location.href.match(/https?:\/\/stackexchange\.com\/?/) || sox.location.matchWithPattern('*://area51.stackexchange.com/*')) return true; |
| 276 | + if (location.href.match(/https?:\/\/stackexchange\.com\/?/) || sox.location.matchWithPattern('*://area51.stackexchange.com/*')) return true; |
273 | 277 | } |
274 | 278 | return false; |
275 | 279 | } |
|
320 | 324 | if (sox.site.type == sox.site.types.chat) { |
321 | 325 | return Chat.RoomUsers.current().name; |
322 | 326 | } else { |
323 | | - return Stack && this.loggedIn ? decodeURI(Stack.options.user.profileUrl.split('/')[5]) : undefined; |
| 327 | + var $uname = sox.NEW_TOPBAR ? $('body > header > div > div.-actions > a > div.gravatar-wrapper-24') : $('body > div.topbar > div > div.topbar-links > a > div.gravatar-wrapper-24'); |
| 328 | + return ($uname.length ? $uname.attr('title') : false); |
324 | 329 | } |
325 | 330 | }, |
326 | 331 | get loggedIn() { |
|
0 commit comments