-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add switch user function add user input label
- Loading branch information
1 parent
0b78e2b
commit ee1c3a2
Showing
4 changed files
with
97 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,60 @@ | ||
|
||
// get data list from storage | ||
let data_list = []; | ||
|
||
let list = document.getElementById('linkList'); | ||
|
||
let links = [ | ||
{ | ||
name: 'HKU Portal', | ||
url: 'https://hkuportal.hku.hk/login.html', | ||
}, | ||
{ | ||
name: 'HKU Moodle (Dashboard)', | ||
url: 'https://moodle.hku.hk/my/', | ||
}, | ||
{ | ||
name: 'HKU Library Booking System', | ||
url: 'https://lib.hku.hk/hkulauth/legacy/authMain?uri=https://booking.lib.hku.hk/getpatron.aspx', | ||
}, | ||
{ | ||
name: 'HKU Exam Base', | ||
url: 'https://exambase-lib-hku-hk.eproxy.lib.hku.hk/exhibits/show/exam/home', | ||
chrome.storage.sync.get(['list', 'username', 'password'], function (items) { | ||
if (items.list !== undefined) { | ||
data_list = items.list; | ||
} else { | ||
if (items.username === undefined) { | ||
// go to options.html | ||
location.href = chrome.runtime.getURL('popup/options.html'); | ||
} else { | ||
data_list = [{ | ||
username: items.username, | ||
password: items.password | ||
}] | ||
} | ||
} | ||
|
||
let list = document.getElementById('linkList'); | ||
|
||
|
||
for (let i = 0; i < data_list.length; i++) { | ||
let div = document.createElement('div'); | ||
div.classList.add('linkWithImage'); | ||
let img = document.createElement('img'); | ||
img.src = 'https://sis-eportal.hku.hk/favicon.ico'; | ||
img.alt = data_list[i].username; | ||
img.width = 20; | ||
img.height = 20; | ||
img.style.marginRight = '10px'; | ||
div.appendChild(img); | ||
let text = document.createTextNode(data_list[i].username); | ||
div.appendChild(text); | ||
list.appendChild(div); | ||
} | ||
]; | ||
|
||
let linkWithImage = document.getElementsByClassName('linkWithImage'); | ||
for (let i = 0; i < linkWithImage.length; i++) { | ||
linkWithImage[i].addEventListener('click', function () { | ||
// save data to storage | ||
chrome.storage.sync.set({ | ||
username: data_list[i].username, | ||
password: data_list[i].password | ||
}); | ||
|
||
for (let i = 0; i < links.length; i++) { | ||
let div = document.createElement('div'); | ||
div.classList.add('linkWithImage'); | ||
let img = document.createElement('img'); | ||
img.src = 'https://sis-eportal.hku.hk/favicon.ico'; | ||
img.alt = links[i].name; | ||
img.width = 20; | ||
img.height = 20; | ||
img.style.marginRight = '10px'; | ||
div.appendChild(img); | ||
let text = document.createTextNode(links[i].name); | ||
div.appendChild(text); | ||
list.appendChild(div); | ||
} | ||
// show notification | ||
// clear body | ||
document.body.innerHTML = ''; | ||
let div = document.createElement('h1'); | ||
div.innerHTML = 'Switch user to ' + data_list[i].username + '.'; | ||
document.body.appendChild(div); | ||
|
||
let linkWithImage = document.getElementsByClassName('linkWithImage'); | ||
for (let i = 0; i < linkWithImage.length; i++) { | ||
linkWithImage[i].addEventListener('click', function () { | ||
chrome.tabs.create({ url: links[i].url }); | ||
}); | ||
} | ||
// close | ||
setTimeout(function () { | ||
window.close(); | ||
}, 1000); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters