-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
126 lines (122 loc) · 4.29 KB
/
logic.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const clock = new Vue({
el: '#app',
data: {
hours: 0,
seconds: 0,
date: moment().locale('ko').format('L') + moment().locale('ko').format('dddd')[0],
countdown: 10,
backgrounds: ['bridge','summer','purple', 'cave', 'winter'],
},
mounted: function() {
setInterval(()=>{
this.hours = [moment().format('LTS').split(':')][0]
this.seconds = [moment().format('LTS').split(':')][0][2].split(' ')
},500)
try {
document.querySelector('html').style.background = `url("./${localStorage.bg}.jpg")`
} catch (error) {
console.log(error)
}
},
methods: {
changeBg(direction) {
const background = document.querySelector('html')
if (direction == 1){
let temp = this.backgrounds.shift()
this.backgrounds.push(temp)
localStorage.bg = temp;
background.style.background = `url("./${this.backgrounds[0]}.jpg")`
} else {
let temp = this.backgrounds.pop()
this.backgrounds.unshift(temp)
localStorage.bg = temp;
background.style.background = `url("./${this.backgrounds[0]}.jpg")`
}
},
}
})
const commitView = new Vue({
el: '#commitView',
data: {
branches: ['master', 'dev'],
currentBranch: 'master',
commits: null,
gitUserName: 'vuejs',
repoName: 'vue',
},
mounted: function() {
if (localStorage.gitUserName) {
this.gitUserName = localStorage.gitUserName;
}
if (localStorage.repoName) {
this.repoName = localStorage.repoName;
}
this.rssData()
},
watch: {
gitUserName(newName) {
localStorage.gitUserName = newName;
},
repoName(newName) {
localStorage.repoName = newName;
}
},
methods: {
commitTrackerVisible() {
const ctCont = document.getElementById('commitTrackerToggle')
if (ctCont.hidden){
ctCont.hidden = false
} else {
ctCont.hidden = true
}
},
fetchData: function () {
const xhr = new XMLHttpRequest()
let apiURL = `https://api.github.com/repos/` + this.gitUserName + '/' + this.repoName + `/commits?per_page=3&sha=`
xhr.open('GET', apiURL + this.currentBranch)
xhr.onload = function () {
this.commits = JSON.parse(xhr.responseText)
const commitdiv = document.getElementById('commits')
commitdiv.innerHTML=
`<div>
<p class="dropdown-item">` + `
<a href="` + this.commits[0].html_url + `" target="_blank">` + this.commits[0].sha.slice(0, 7)+`</a>
- <span class="message">` + this.commits[0].commit.message + `</span>
by <span><a href="` + this.commits[0].author.html_url + `" target="_blank">` + this.commits[0].commit.author.name + `</a></span>
at <span>` + this.commits[0].commit.author.date.replace(/T|Z/g, ' ') + `</span>
</p>
<p class="dropdown-item">` + `
<a href="` + this.commits[1].html_url + `" target="_blank">` + this.commits[1].sha.slice(0, 7)+`</a>
- <span class="message">` + this.commits[1].commit.message + `</span>
by <span><a href="` + this.commits[1].author.html_url + `" target="_blank">` + this.commits[1].commit.author.name + `</a></span>
at <span>` + this.commits[1].commit.author.date.replace(/T|Z/g, ' ') + `</span>
</p>
<p class="dropdown-item">` + `
<a href="` + this.commits[2].html_url + `" target="_blank">` + this.commits[2].sha.slice(0, 7)+`</a>
- <span class="message">` + this.commits[2].commit.message + `</span>
by <span><a href="` + this.commits[2].author.html_url + `" target="_blank">` + this.commits[2].commit.author.name + `</a></span>
at <span>` + this.commits[2].commit.author.date.replace(/T|Z/g, ' ') + `</span>
</p>
</div>`
}
xhr.send()
},
rssData: function () {
let feed = "http://www.zdnet.co.kr/Include2/NewsSection0020.xml?format=xml";
let xhr = new XMLHttpRequest;
xhr.open('GET', feed);
xhr.responseType = 'document';
xhr.overrideMimeType('text/xml');
xhr.onload = function () {
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
const totalItemCount = xhr.responseXML.getElementsByTagName('item').length
const rssDiv = document.getElementById('rss')
for (let i=0;i < totalItemCount;i++){
rssDiv.innerHTML += `<a href="` + xhr.responseXML.getElementsByTagName('item')[i].getElementsByTagName('link')[0].textContent + ` target="_blank"><h3 class="shadow bg-white">` + xhr.responseXML.getElementsByTagName('item')[i].getElementsByTagName('title')[0].textContent + `</h3></a>`
}
}
};
xhr.send();
}
},
})