function loadNextPage() { chrome.extension.sendRequest({"action": "nextTitleUrl"}, function(nextUrl) { window.location = nextUrl; }); } function skipMovie() { chrome.extension.sendRequest( { "action": "unknownMovie", "url": window.location.href }); loadNextPage(); } function setClicked(div, clickedByUser) { div.style.backgroundColor = 'lightgreen'; div.isClicked = true; if (clickedByUser && ++quotesSubmitted == 1) { infobox.removeChild(skipButton); infobox.removeChild(spacer); } } document.addEventListener('keypress', function(e) { var element = e.target; if (element.nodeType == 3) element = element.parentNode; if (element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return; if (e.charCode == 115 /* s */) skipMovie(); else if (e.charCode == 110 /* n */) loadNextPage(); }); //Remove advertisement: var advertisement = document.getElementById("tn15adrhs"); if (advertisement != null) advertisement.parentNode.removeChild(advertisement); var infobox = document.createElement('div'); var title = document.createElement('strong'); title.innerText = "AnyClip Moment Selector"; var skipButton = document.createElement('strong'); skipButton.style.float = 'right'; skipButton.innerText = "Never Seen/Don't Know It"; skipButton.style.cursor = 'pointer'; skipButton.style.color = '#F78181'; skipButton.style.textDecoration = 'underline'; skipButton.addEventListener('click', skipMovie); skipButton.title = "keyboard shortcut: s"; var nextButton = document.createElement('strong'); nextButton.style.float = 'right'; nextButton.innerText = "Finished Selecting, Next Movie"; nextButton.style.cursor = 'pointer'; nextButton.style.color = '#F78181'; nextButton.style.textDecoration = 'underline'; nextButton.addEventListener('click', loadNextPage); nextButton.title = "keyboard shortcut: n"; var levelSelect = document.createElement('select'); levelSelect.style.float = 'right' var novice = document.createElement('option'); novice.text = "Level 1: Novice"; var movieLover = document.createElement('option'); movieLover.text = "Level 2: Movie Lover"; var totalGeek = document.createElement('option'); totalGeek.text = "Level 3: Total Geek"; levelSelect.add(novice, null); levelSelect.add(movieLover, null); levelSelect.add(totalGeek, null); chrome.extension.sendRequest({'action': 'getLevel'}, function(level) { levelSelect.selectedIndex = level - 1; }); levelSelect.addEventListener('change', function() { chrome.extension.sendRequest( { 'action' : 'setLevel', 'level': levelSelect.selectedIndex + 1 }, loadNextPage); var loading = document.createElement('option'); loading.text = "Loading new level..."; levelSelect.add(loading); levelSelect.selectedIndex = 3; levelSelect.disabled = true; }); var spacer = document.createElement('div'); spacer.style.float = 'right'; spacer.innerHTML = "    "; infobox.appendChild(title); infobox.appendChild(skipButton); infobox.appendChild(spacer); infobox.appendChild(nextButton); infobox.appendChild(spacer.cloneNode(true)); infobox.appendChild(levelSelect); infobox.style.background = '#36b'; infobox.style.borderBottom = '1px dotted white'; infobox.style.color = '#fff'; infobox.style.padding = '10px'; infobox.style.position = 'relative'; infobox.style.zIndex = '123456'; infobox.style.font = '13px Arial'; document.body.insertBefore(infobox, document.body.firstChild); var divRegEx = /^qt[0-9]{7}$/; var divs = document.getElementsByTagName('div'); var quotesSubmitted = 0; for (var i = 0; i < divs.length; i++) { if (divRegEx.test(divs[i].id)) { divs[i].isClicked = false; divs[i].addMomentLink = document.createElement('div'); divs[i].addMomentLink.style.position = 'relative'; divs[i].addMomentLink.style.top = '-' + divs[i].offsetHeight.toString() + 'px'; divs[i].addMomentLink.style.backgroundColor = '#FE9A2E'; divs[i].addMomentLink.style.width = divs[i].offsetWidth + "px"; divs[i].addMomentLink.style.height = divs[i].offsetHeight + "px"; divs[i].addMomentLink.style.visibility = 'hidden'; divs[i].addMomentLink.style.opacity = '.66'; divs[i].addMomentLink.style.cursor = 'pointer'; var txt = document.createElement('h3'); txt.innerText = "Add this quote as an AnyClip moment"; txt.align = "center"; txt.style.height = divs[i].addMomentLink.style.height; txt.style.position = 'relative'; txt.style.top = '10px'; txt.style.opacity = '1'; divs[i].addMomentLink.appendChild(txt); var oldHeight = divs[i].offsetHeight; divs[i].appendChild(divs[i].addMomentLink); divs[i].style.height = oldHeight + "px"; divs[i].addEventListener('mouseover', function() { if (!this.isClicked) this.addMomentLink.style.visibility = 'visible'; }, false); divs[i].addEventListener('mouseout', function() { this.addMomentLink.style.visibility = 'hidden'; }, false); divs[i].addEventListener('click', function() { if (!this.isClicked) { var momentName = prompt("How should I name this moment?\n\nRemember that the moment name will become a part of the URL on AnyClip, so:\n\n1. Name it with words you think people would use when they search for it.\n\n2. Also consider it will be seen internally in a list of results, so make sure it's specific to the moment and helps people select the right moment.\n\n3. Try (not a must) to keep the name to under 6 words\n\n4. Don't use the movie name in the title\n\n5. Be unique (per movie)!", ""); if (momentName != null && momentName != "") { this.addMomentLink.style.visibility = 'hidden'; this.style.backgroundColor = 'gold'; this.isClicked = true; var me = this; chrome.extension.sendRequest( { 'action' : 'submitMoment', 'url': window.location.href, 'momentName': momentName, 'quote': this.innerText.replace("\nShare this quote", "").replace(/^\s\s*/, '').replace(/\s\s*$/, ''), 'quoteID': me.id }, function(success) { if (success) setClicked(me, true); else { me.style.backgroundColor = 'darksalmon'; setTimeout(function() { me.style.backgroundColor = ''; me.isClicked = false; }, 2000); } }); } } }, false); } } chrome.extension.sendRequest( { 'action': 'getAlreadySubmitted', 'url': window.location.href }, function(list) { for (var i = 0; i < list.length; i++) { var div = document.getElementById(list[i]); if (div != null) setClicked(div, false); } });