-
Notifications
You must be signed in to change notification settings - Fork 1
/
quoteback.js
67 lines (55 loc) · 2.76 KB
/
quoteback.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
document.addEventListener("DOMContentLoaded", function(){
var index = document.getElementsByClassName("quoteback");
for (item in index){
var text = index[item].childNodes[1].innerHTML;
var url = index[item].cite;
var author = index[item].getAttribute("data-author");
var title = index[item].getAttribute("data-title");
var favicon = "https://s2.googleusercontent.com/s2/favicons?domain_url="+url+"&sz=64"
var component = `
<quoteback-component>
<span slot="portal-content">${text}</span>
<span slot="portal-author">${author}</span>
<span slot="portal-title">${title}</span>
<a target="_blank" class="portal-arrow-519256" href="${url}" slot="portal-link">Go to text <span class="right-arrow">→</span></a>
<img slot="mini-favicon-519256" href="${favicon}">
<script src="./quoteback.js"></script>
</quoteback-component>
`;
var newEl = document.createElement('div');
newEl.innerHTML = component;
// replace el with newEL
index[item].parentNode.replaceChild(newEl, index[item]);
const template = document.createElement('template');
template.innerHTML=`
<link rel="stylesheet" type="text/css" href="https://files-lovat-six.now.sh/quote.css">
<div class="portal-container-519256">
<div id="portal-parent-519256" class="portal-parent-519256">
<div class="portal-content-519256"><slot name="portal-content"></slot></div>
</div>
<div class="portal-head-519256">
<div class="portal-avatar-519256"><img class="mini-favicon-519256" src=""/></div>
<div class="portal-metadata-519256">
<div class="portal-title-519256">
<div class="portal-author-519256"><slot name="portal-author"></slot></div>
<div class="title-wrapper-519256"><slot name="portal-title"></slot></div>
</div>
</div>
<div class="portal-backlink-519256"><slot name="portal-link" target="_blank" href="" class="portal-arrow-519256">Go to text <span class="right-arrow">→</span></a></div>
</div>
</div>`;
class QuoteBack extends HTMLElement {
constructor(){
super();
this.attachShadow({mode: 'open'});
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
console.log(customElements.get('quoteback-component'));
if (customElements.get('quoteback-component')){
null;
}else{
window.customElements.define('quoteback-component', QuoteBack)
}
}
});