-
Notifications
You must be signed in to change notification settings - Fork 9
/
inner4.js
101 lines (90 loc) · 5.89 KB
/
inner4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var port = chrome.extension.connect({name: "inner"});
function init(){
if(!document.getElementById('summary-view')) return setTimeout(init, 100);
var share = document.getElementById('summary-view').firstChild.nextSibling;
share.style.padding = '0px';
share.style.paddingLeft = '20px';
share.style.paddingRight = '20px';
var reminder = document.createElement('div');
reminder.style.padding = '18px 2px 17px 0px';
reminder.innerHTML = '<a href="javascript:void(0)" id="surplusback"><span style="font-size:110%;font-weight:bold">‹ Back to Notifications</span></a> <span style="float:right"> <iframe id="plusone_button" style="margin-bottom: -3px;height:15px;width:70px;border:0" src="'+chrome.extension.getURL('plusone.html')+'"></iframe> <a href="javascript:void(0)" id="sharesurplus">Share</a> Surplus!</span>';
share.insertBefore(reminder, share.firstChild);
document.getElementById('sharesurplus').onclick = function(){
setShareURL("https://chrome.google.com/webstore/detail/pfphgaimeghgekhncbkfblhdhfaiaipf", true);
}
document.getElementById('surplusback').onclick = function(){
port.postMessage({action: 'notifications'})
}
var div = document.querySelectorAll('#summary-view>div>div>div:first-child');
for(var i = 0; i < div.length; i++){
if(div[i].innerHTML == div[i].innerText && div[i].innerText){
break;
}
}
div = div[i];
var text = "Notifications";
div.innerHTML = "<style>#summary-content{width:440px}</style><div id='sharebutton' style='cursor:pointer;background: -webkit-linear-gradient(top,whiteSmoke,#F1F1F1);border: 1px solid rgba(0, 0, 0, 0.1);color: #666;border-radius: 4px;width:16px;height:16px;padding:3px 8px;display:inline'>Share</div> <div id='reloadbutton' style='cursor:pointer;height:15px;position:relative;top:7px;background: url(\""+chrome.extension.getURL('img/view-refresh.png')+"\") 2px 3px no-repeat, -webkit-linear-gradient(top,whiteSmoke,#F1F1F1);background: url(\""+chrome.extension.getURL('img/view-refresh.png')+"\") 2px 3px no-repeat;border: 1px solid rgba(0, 0, 0, 0.1);color: #666;border-radius: 4px;padding:3px 10px;display:inline-block'></div> <div id='popoutbutton' style='cursor:pointer;background: url(\""+chrome.extension.getURL('img/popout.png')+"\") 2px 3px no-repeat,-webkit-linear-gradient(top,whiteSmoke,#F1F1F1);background: url(\""+chrome.extension.getURL('img/popout.png')+"\") 2px 3px no-repeat;border: 1px solid rgba(0, 0, 0, 0.1);color: #666;border-radius: 4px;padding:3px 10px;display:inline-block;height:15px;position:relative;top:7px;'></div> <div id='settingsbutton' style='cursor:pointer;height:15px;position:relative;top:7px;background: url(\""+chrome.extension.getURL('img/wrench.png')+"\") 2px 3px no-repeat,-webkit-linear-gradient(top,whiteSmoke,#F1F1F1);background: url(\""+chrome.extension.getURL('img/wrench.png')+"\") 2px 3px no-repeat;border: 1px solid rgba(0, 0, 0, 0.1);color: #666;border-radius: 4px;padding:3px 10px;display:inline-block'></div>";
document.getElementById('sharebutton').onclick = function(){
port.postMessage({action: 'sharebox'})
}
document.getElementById('reloadbutton').onclick = function(){
port.postMessage({action: 'reload'})
}
document.getElementById('popoutbutton').onclick = function(){
port.postMessage({action: 'popout'})
}
document.getElementById('settingsbutton').onclick = function(){
port.postMessage({action: 'settings'})
}
}
function mouse(name){
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent(name ? ('mouse'+name) : 'click', true, true, window, 0, 0, 0, 1, 1, false, false, false, false, 0, null);
return evt;
}
function focusText(){
setTimeout(function(){
document.querySelector("div[contenteditable='plaintext-only']").focus()
}, 100);
}
function setShareURL(url, force){
(function(){
if(document.querySelector("div[contenteditable='plaintext-only']") && document.querySelector("span[title='Add link']").offsetHeight){
if(document.querySelectorAll("#summary-view>div")[0].querySelector('a[href="'+url+'"]')) return focusText();
if(!force && document.querySelector("div[contenteditable='plaintext-only']").innerText.trim() != '') return focusText();
try{
[].slice.call(document.querySelectorAll("#summary-view>div")[0].querySelectorAll('div[tabindex="0"]'),0)
.filter(function(e){return(getComputedStyle(e).right=='11px')})[0].dispatchEvent(mouse());
}catch(err){}
setTimeout(function(){
document.querySelector("span[title='Add link']").dispatchEvent(mouse());
var evt = document.createEvent("KeyboardEvent");
evt.initEvent ("keypress", true, true, window, 0, 0, 0, 0, 0, 42)
document.querySelector('td>div>input[type=text]').dispatchEvent(evt);
document.querySelector('td>div>input[type=text]').value = url;
if(/https?:/.test(url)){
setTimeout(function(){
var addbtn = document.querySelector('td>div div[role=button]');
addbtn.dispatchEvent(mouse('down'));
addbtn.dispatchEvent(mouse('up'));
focusText()
}, 100)
}
}, 100);
}else setTimeout(arguments.callee, 100);
})()
}
port.onMessage.addListener(function(msg){
if(msg.user && document.getElementById('usersettings')) document.getElementById('usersettings').innerText = msg.user;
if(msg.action == "share"){
if(msg.current_url) setShareURL(msg.current_url);
if(document.getElementById('plusone_button'))
document.getElementById('plusone_button').src = chrome.extension.getURL('plusone.html')+'?'+encodeURIComponent(msg.current_url);
}else if(msg.action == 'editing'){
var editing = document.activeElement.isContentEditable&&!!document.activeElement.innerText.trim();
port.postMessage({action: 'editing', value: editing});
} if(msg.action == 'accept'){
console.log('Recieved acceptance letter.');
init();
}
})