1
0
This repository has been archived on 2025-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
binsearchplus/src/content.coffee

62 lines
2.2 KiB
CoffeeScript

# Binsearch+
# @author Markus Birth <markus@birth-online.de>
console.log 'Binsearch+'
# Add "+" to title
document.title = document.title.replace 'Binsearch', 'Binsearch+'
# Replace favicon by our "b+" one (http://stackoverflow.com/questions/260857/changing-website-favicon-dynamically)
iconurl = chrome.extension.getURL 'binsearchplus_16.png'
console.log 'Icon is: %o', iconurl
favicon = document.querySelector("link[rel*='icon']") || document.createElement 'link'
favicon.type = 'image/png'
favicon.rel = 'shortcut icon'
favicon.href = iconurl
document.getElementsByTagName('head')[0].appendChild favicon
# Make labels of radiobuttons clickable
idctr = 0
inputs = document.getElementsByTagName 'input'
for input in inputs
continue if input.type isnt 'radio'
console.log 'Found %o', input
# Add element id
inputid = document.createAttribute 'id'
inputid.value = "lbl#{idctr++}"
input.attributes.setNamedItem inputid
# Add <label> around following text
textElem = input.nextSibling
span = document.createElement 'label'
span.innerHTML = textElem.textContent
spanfor = document.createAttribute 'for'
spanfor.value = input['id']
span.attributes.setNamedItem spanfor
textElem.replaceWith span
# Make rows of results table clickable
tbl = document.getElementById 'r2'
rows = tbl.querySelectorAll 'tr'
for row in rows
row.onclick = (e) ->
#console.log 'Clicked %o with %o', this, e
chckbx = this.querySelector 'input[type="checkbox"]'
chckbx.checked = !chckbx.checked
# Add unselect-all button
buttons = document.getElementsByClassName 'b'
for btn in buttons
continue if btn.value isnt 'Create NZB'
spacer1 = document.createTextNode ' '
btn.parentNode.insertBefore spacer1, btn
newbtn = document.createElement 'input'
newbtn.type = 'button'
newbtn.className = 'b'
newbtn.value = 'Unselect all'
newbtn.onclick = ->
for cbx in document.getElementById('r2').querySelectorAll('input[type="checkbox"]')
cbx.checked = false
btn.parentNode.insertBefore newbtn, btn
spacer2 = document.createTextNode ' '
btn.parentNode.insertBefore spacer2, btn
break