Last active
December 31, 2015 10:50
-
-
Save nodegin/d3c67ab90edb4f4ccc78 to your computer and use it in GitHub Desktop.
aikon core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # aikon core, copyright 2015&+ nodegin, version 3 | |
| class Aikon | |
| base: 'https://na.cx/i/' | |
| icons: {} | |
| defc: ['[369]','#adore#','#yup#','O:-)',':-[','#ass#','[banghead]',':document','[bomb]','[bouncer]','[bouncy]','#bye#','[censored]','#cn#',':o)',':~(','xx(',':-]','#ng#','#fire#','[flowerface]',':-(','fuck','@_@','#good#','#hehe#','#hoho#','#kill2#','#kill#','^3^','#love#','#no#','[offtopic]',':O','[photo]','[shocking]','[slick]',':)','[sosad]','#oh#',':P',';-)','???','?_?','[yipes]','Z_Z','#lol#'] | |
| defi: ['369', 'adore', 'agree', 'angel', 'angry', 'ass', 'banghead', 'biggrin', 'bomb', 'bouncer', 'bouncy', 'bye', 'censored', 'chicken', 'clown', 'cry', 'dead', 'devil', 'donno', 'fire', 'flowerface', 'frown', 'fuck', '@', 'good', 'hehe', 'hoho', 'kill2', 'kill', 'kiss', 'love', 'no', 'offtopic', 'oh', 'photo', 'shocking', 'slick', 'smile', 'sosad', 'surprise', 'tongue', 'wink', 'wonder2', 'wonder', 'yipes', 'z', 'lol'] | |
| init: (data)=> | |
| # add icon buttons | |
| frag = document.createDocumentFragment() | |
| for ent in data.feed.entry | |
| continue if +ent.gsx$hi.$t is 1 | |
| code = ent.gsx$cd.$t | |
| @icons[code] = {} | |
| @icons[code].spec = +ent.gsx$sp.$t is 1 | |
| @icons[code].prev = (if code is 'hkg' then '' else @base) + ent.gsx$pv.$t | |
| @icons[code].refc = ent.gsx$rf.$t.replace /^\|+|\|+$/g, '' | |
| @icons[code].refc = if @icons[code].refc.length > 0 then @icons[code].refc.split('|') else [] | |
| @icons[code].icon = ent.gsx$ic.$t.replace /\.(g|p)/g, (a, b) -> | |
| '.' + (if b is 'g' then 'gif' else 'png') | |
| .replace /^\|+|\|+$/g, '' | |
| @icons[code].icon = if @icons[code].icon.length > 0 then @icons[code].icon.split('|') else [] | |
| frag.appendChild $('<span id="toggemt-' + code + '" class="btn" title="' + ent.gsx$ds.$t + '"> | |
| <img alt src="' + @icons[code].prev + '" style="vertical-align:middle"> | |
| </span>')[0] | |
| document.querySelector('#gae .edt').appendChild frag | |
| fn = (e)-> | |
| $(e).find('img[data-original*="i.na.cx"]').each -> | |
| this.setAttribute 'src', this.getAttribute('data-original').replace('i.na.cx', 'na.cx/i') | |
| fn '#main' | |
| node = document.querySelector('#main article') | |
| if node isnt null | |
| new MutationObserver (mutations)=> | |
| mutations.forEach (mutation)=> | |
| fn mutation.addedNodes | |
| .observe node, { childList: yes } | |
| # hijack events | |
| document.querySelector('#gae .edt #toggemt').removeAttribute 'onclick' | |
| @swap (@getPref 'previousUsed', 'hkg'), no | |
| textarea = $('#gae #ta') | |
| $(document).on 'click.aikon', '[id^="toggemt"]', (e)=> | |
| @swap if e.currentTarget.id.indexOf('-') > 0 then e.currentTarget.id.split('-')[1] else 'hkg' | |
| isReply = (document.URL.indexOf 'reply/') > -1 | |
| if (document.URL.indexOf 'view/') > -1 | |
| ev = $._data(document, 'events').click | |
| k = ev.length | |
| while --k >= 0 | |
| if ev[k].selector is '#submit_fast_reply' | |
| handlr = ev[k].handler | |
| ev[k].handler = (e) => | |
| e.preventDefault() | |
| textarea.val @repl textarea.val() | |
| handlr e | |
| else if document.URL.indexOf('post/') > -1 or document.URL.indexOf('poll/') > -1 or isReply | |
| $('#reply_topic').attr 'onsubmit', 'return !1' if isReply | |
| ev = $._data(document, 'events').submit | |
| k = ev.length | |
| while --k >= 0 | |
| if ev[k].selector is '#post_new_topic' or ev[k].selector is '#reply_topic' | |
| handlr = ev[k].handler | |
| ev[k].handler = (e) => | |
| e.preventDefault() | |
| textarea.val @repl textarea.val() | |
| handlr e | |
| getPref: (key, def)-> | |
| localStorage['_aikon_' + key] or def | |
| setPref: (key, value)-> | |
| localStorage['_aikon_' + key] = value | |
| swap: (code, open = yes)-> | |
| builtIn = code is 'hkg' | |
| tray = document.querySelector('#gae .emt') | |
| frag = document.createDocumentFragment() | |
| newTray = document.createElement 'div' | |
| newTray.className = tray.className | |
| newTray.style.display = tray.style.display | |
| for i in [0 ... (if builtIn then @defc else @icons[code].icon).length] | |
| url = if builtIn then '/face/hkg/' + @defi[i] + '.gif' else @base + @icons[code].icon[i] | |
| c = if builtIn then @defc[i] else if @icons[code].spec then @icons[code].refc[i] else @defc[i] + code | |
| dc = if not builtIn then "[img]#{url}[/img]" else c | |
| frag.appendChild $('<a href="#" data-code="'+ dc + '"><img alt="' + c + '" src="' + url + '"> </a>')[0] | |
| newTray.appendChild frag | |
| tray.parentNode.replaceChild newTray, tray | |
| lo = @getPref 'previousUsed', 'hkg' | |
| needOpen = code is lo or code isnt lo and tray.style.display is 'none' | |
| $(newTray).slideToggle 150 if open and needOpen | |
| @setPref 'previousUsed', code | |
| repl: (content, prev = no) -> | |
| for code of @icons | |
| if !@icons[code].spec | |
| for icon, i in @icons[code].icon | |
| while (content.indexOf @defc[i] + code) isnt -1 | |
| content = content.replace @defc[i] + code, | |
| if prev then '<img alt src="' + @base + icon + '">' | |
| else '[img]' + @base + icon + '[/img]' | |
| else | |
| for icon, i in @icons[code].icon | |
| while (content.indexOf @icons[code].refc[i]) isnt -1 | |
| content = content.replace @icons[code].refc[i], | |
| if prev then '<img alt src="' + @base + icon + '">' | |
| else '[img]' + @base + icon + '[/img]' | |
| content | |
| new Aikon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name aikon | |
| // @icon http://na.cx/i/1wng8.gif | |
| // @namespace xxx | |
| // @include /^https?:\/\/.*hkgalden\.com\/(view|reply|post|poll).*$/ | |
| // @version 3.0 | |
| // @grant GM_getResourceText | |
| // @require https://na.cx/uvUqa | |
| // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js | |
| // @resource prog https://na.cx/ibice | |
| // @resource list https://na.cx/nyelo | |
| // @run-at document-end | |
| // ==/UserScript== | |
| this.$ = this.jQuery = jQuery.noConflict(true); | |
| this.Aikon = function (d) { CoffeeScript.eval(GM_getResourceText('prog')).init(d) }; | |
| $(function(){ | |
| if (!$('#gb .actp a[href="/member/logout"]').length) return; | |
| eval(GM_getResourceText('list')); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment