CoffeeScript optimization
This commit is contained in:
parent
1cadf32e29
commit
eb2fa98641
@ -1,23 +1,23 @@
|
|||||||
blacklistFilter = (blacklist) ->
|
blacklistFilter = (blacklist) ->
|
||||||
if not blacklist then return
|
if not blacklist then return
|
||||||
nodes = document.getElementsByClassName('Tg')
|
nodes = document.getElementsByClassName('Tg')
|
||||||
for own i of nodes
|
for node, i in nodes
|
||||||
hideBtn = nodes[i].getElementsByClassName('hidden')
|
hideBtn = node.getElementsByClassName('hidden')
|
||||||
if hideBtn[0]
|
if hideBtn[0]
|
||||||
contents = nodes[i].getElementsByClassName('qf')
|
contents = node.getElementsByClassName('qf')
|
||||||
contents[0]?.style.display = 'block'
|
contents[0]?.style.display = 'block'
|
||||||
nodes[i].removeChild(hideBtn[0])
|
node.removeChild(hideBtn[0])
|
||||||
|
|
||||||
for own j of blacklist
|
for blentry, j in blacklist
|
||||||
if nodes[i].innerHTML.toLowerCase().indexOf(blacklist[j].toLowerCase()) is -1
|
continue if node.innerHTML.toLowerCase().indexOf(blentry.toLowerCase()) is -1
|
||||||
continue
|
|
||||||
contents = nodes[i].getElementsByClassName('qf')
|
contents = node.getElementsByClassName('qf')
|
||||||
contents[0]?.style.display = 'none'
|
contents[0]?.style.display = 'none'
|
||||||
|
|
||||||
newdiv = document.createElement('div')
|
newdiv = document.createElement('div')
|
||||||
newdiv.setAttribute('id', "blacklist_item_#{i}")
|
newdiv.setAttribute('id', "blacklist_item_#{i}")
|
||||||
newdiv.setAttribute('class', 'hidden')
|
newdiv.setAttribute('class', 'hidden')
|
||||||
newdiv.innerHTML = "Hidden: \"#{blacklist[j]}\""
|
newdiv.innerHTML = "Hidden: \"#{blentry}\""
|
||||||
|
|
||||||
newbtn = document.createElement('input')
|
newbtn = document.createElement('input')
|
||||||
newbtn.setAttribute('type', 'button')
|
newbtn.setAttribute('type', 'button')
|
||||||
@ -32,13 +32,13 @@ blacklistFilter = (blacklist) ->
|
|||||||
newbtn.addEventListener('click', removeFunc, false)
|
newbtn.addEventListener('click', removeFunc, false)
|
||||||
newdiv.appendChild(newbtn)
|
newdiv.appendChild(newbtn)
|
||||||
|
|
||||||
nodes[i].appendChild(newdiv)
|
node.appendChild(newdiv)
|
||||||
|
|
||||||
blacklist = ->
|
blacklist = ->
|
||||||
chrome.extension.sendRequest(
|
chrome.extension.sendRequest(
|
||||||
method: 'getBlacklist',
|
method: 'getBlacklist',
|
||||||
(response) ->
|
(response) ->
|
||||||
if response.blacklist then blacklistFilter(response.blacklist)
|
blacklistFilter(response.blacklist) if response.blacklist
|
||||||
)
|
)
|
||||||
|
|
||||||
chrome.extension.onMessage.addListener( (request, sender, sendResponse) -> blacklistFilter(request.blacklist) )
|
chrome.extension.onMessage.addListener( (request, sender, sendResponse) -> blacklistFilter(request.blacklist) )
|
||||||
|
@ -3,12 +3,12 @@ readBlacklist = ->
|
|||||||
blacklistItemsDiv = document.getElementById('blacklist_items')
|
blacklistItemsDiv = document.getElementById('blacklist_items')
|
||||||
blacklistItemsDiv.innerHTML = ''
|
blacklistItemsDiv.innerHTML = ''
|
||||||
if not needles then return
|
if not needles then return
|
||||||
for own i of needles
|
for needle, i in needles
|
||||||
color = if i%2 is not 0 then 'dark' else 'light'
|
color = if i%2 is not 0 then 'dark' else 'light'
|
||||||
newdiv = document.createElement('div')
|
newdiv = document.createElement('div')
|
||||||
newdiv.setAttribute('id', "blacklist_item_#{i}")
|
newdiv.setAttribute('id', "blacklist_item_#{i}")
|
||||||
newdiv.setAttribute('class', "blacklist_item #{color}")
|
newdiv.setAttribute('class', "blacklist_item #{color}")
|
||||||
newdiv.innerHTML = "<div>#{needles[i]}</div>"
|
newdiv.innerHTML = "<div>#{needle}</div>"
|
||||||
|
|
||||||
newbtn = document.createElement('input')
|
newbtn = document.createElement('input')
|
||||||
newbtn.setAttribute('type', 'button')
|
newbtn.setAttribute('type', 'button')
|
||||||
|
Reference in New Issue
Block a user