Skip to content

Commit

Permalink
Merge pull request #16 from khengyun/edu@v3
Browse files Browse the repository at this point in the history
update setting popup UI
  • Loading branch information
khengyun authored Nov 10, 2022
2 parents 8fc6707 + a37fbe9 commit bbc6ffa
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 70 deletions.
Binary file added assets/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions doc_script/_doc_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function push_user_ingroup(push_data) {
post_point_to_server.then((e) => {
// console.log(e)
//log some thing here
}).catch((e)=>{
console.log(e.message)
})
}

Expand All @@ -43,6 +45,7 @@ function get_evaluate_inside_group_score(input_data) {
js_data.goodPoint = point;
js_data.cooperativePoint = point;
list_user_point.push(JSON.stringify(js_data))

if (list_user_point.length === members.length) {
push_user_ingroup({
"body": list_user_point,
Expand Down Expand Up @@ -130,15 +133,16 @@ function get_list_present_critical(get_list_present) {
}


if (presentation_grading && work ) {
if (presentation_grading ) {
evaluate_present({
"present_id": present_id,
"title": title,
"url": 'https://fuapi.edunext.vn/learn/v2/classes/presentcritical/evaluate-present',
})
}

if (group_members_grading && work) {
if (group_members_grading ) {

Individual_grade({
"sessionId": sessionId,
"activityId": activityId,
Expand Down Expand Up @@ -235,7 +239,7 @@ function __main__() {

setInterval(function () {
const element = document.getElementsByClassName("course-infor");
let text_null = element[0].getElementsByTagName("a")[1]
let text_null = element[0]?.getElementsByTagName("a")[1].innerText ;

if (text_null !== undefined ){
for (let i = 0; i < element.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"default_title": "AutoNext",
"default_popup": "pop_script/popup.html"
},
"version": "3.0.0",
"version": "3.2.3",
"description": "This automatic grading tool on edunext\n__Hovilo__",
"manifest_version": 3,
"permissions": [
Expand Down
7 changes: 7 additions & 0 deletions pop_script/active_page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
console.log("some thign")
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = tabs[0].url;
if (!url.includes('https://fu.edunext.vn/')) {
document.getElementById('container').innerHTML = '<div>Please Switch To <a href="https://fu.edunext.vn/"> EDUNEXT </a> Tab To Edit Settings</div>'
}
});
20 changes: 13 additions & 7 deletions pop_script/bachground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// localStorage.setItem({key: value}, function() {
// console.log('Value is set to ' + value);
// });
//
// localStorage.getItem(['key'], function(result) {
// console.log('Value currently is ' + result.key);
// });



chrome.action.onClicked.addListener((tab) => {

console.log("some thign")
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = tabs[0].url;
if (!url.includes('https://fu.edunext.vn/')) {
document.getElementById('container').innerHTML = '<div>Please Switch To <a href="https://fu.edunext.vn/"> EDUNEXT </a> Tab To Edit Settings</div>'
}
});
});
30 changes: 27 additions & 3 deletions pop_script/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ image {
.container {
min-height: 75px;
border-bottom: solid 1px rgba(163, 163, 163, 0.3);
display: flex;
justify-content: center;
align-items: center;
}

footer {
Expand Down Expand Up @@ -223,8 +226,8 @@ footer {
content: attr(data-c-tooltip);
font-size: 14px;
line-height: 1.2;

width: 150px;
text-align: center;
width: 50px;
height: auto;
border-radius: 3px;
}
Expand Down Expand Up @@ -330,4 +333,25 @@ footer {
[tooltip-position='right']:after {
margin-left: 0;
margin-bottom: -16px;
}
}

#version{
position: absolute;
right: 20px;
/* left: 5px; */
font-size: small;
}














16 changes: 10 additions & 6 deletions pop_script/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>

<title>AutoNext</title>
<link
crossorigin="anonymous"
Expand Down Expand Up @@ -31,17 +32,15 @@
<h4 class="title">AutoNext</h4>

</div>
<div class="button_on_off_box" id="button_on_off_id" data-c-tooltip="AutoNext on/off" tooltip-position ="left">
<svg id="button_on_off" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
<div class="button_on_off_box" data-c-tooltip="AutoNext on/off" id="button_on_off_id" tooltip-position="left">
<svg id="button_on_off" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
<path d="M288 32c0-17.7-14.3-32-32-32s-32 14.3-32 32V256c0 17.7 14.3 32 32 32s32-14.3 32-32V32zM143.5 120.6c13.6-11.3 15.4-31.5 4.1-45.1s-31.5-15.4-45.1-4.1C49.7 115.4 16 181.8 16 256c0 132.5 107.5 240 240 240s240-107.5 240-240c0-74.2-33.8-140.6-86.6-184.6c-13.6-11.3-33.8-9.4-45.1 4.1s-9.4 33.8 4.1 45.1c38.9 32.3 63.5 81 63.5 135.4c0 97.2-78.8 176-176 176s-176-78.8-176-176c0-54.4 24.7-103.1 63.5-135.4z"/>
</svg>
</div>



</div>

<div class="container">
<div class="container" id="container">
<div class="alert alert-warning">
<div class="setting_table" id="setting_table">
<div class="setting_block">
Expand Down Expand Up @@ -94,16 +93,20 @@ <h5 class="name_setting_block">Presentation Grading</h5>
</div>


<div class="setting_block button_setting_block" id="setting_button_block">
<div class="button_setting_block" id="setting_button_block">
<!-- <h5 class="name_setting_block done_setting_block">Updated settings!</h5>-->
<div></div>
<div class="button_setting">
<button id="apply_button" name="apply_button" value="apply_button"> Apply</button>
</div>
</div>

</div>

</div>
<div id="version">version</div>
</div>

<footer>
<div class="rounded-social-buttons">
<a class="social-button facebook" href="https://www.facebook.com/niraitoo" target="_blank"><i
Expand All @@ -113,6 +116,7 @@ <h5 class="name_setting_block">Presentation Grading</h5>
</div>
</footer>

<script src="./active_page.js" type="text/javascript"></script>
<script src="./popup.js" type="text/javascript"></script>
</body>
</html>
123 changes: 84 additions & 39 deletions pop_script/popup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const version = chrome.runtime.getManifest().version
const elmColors = document.getElementsByName("apply_button");
document.getElementById('version').innerText = `v${version}`

const colors = ["red", "blue"];

let json_data = {
"present_point": 0,
"Individual_point": 0,
Expand All @@ -9,67 +13,108 @@ let json_data = {
"work": true
}

function post_on_off(data){
localStorage.setItem("setting_value", JSON.stringify(data))
location.reload();
async function handleAlarm() {
try {
await chrome.action.setIcon({
path: {
'128': '../assets/image.png'
},
});
} catch (err) {
console.error(err);
}
}


function post_on_off(data) {
localStorage.setItem("setting_value", JSON.stringify(data))
location.reload();
}


const on_off_icon = document.getElementById("button_on_off");

function set_on_off_tooltip(){
function set_on_off_tooltip() {
let dt = JSON.parse(localStorage.getItem("setting_value"))
let set_on_off = document.getElementById("button_on_off_id");
set_on_off.setAttribute("data-c-tooltip", `AutoNext` +` ${dt.work}`.toUpperCase())


console.log(chrome.runtime.getManifest().version);
if (dt.work){
set_on_off.setAttribute("data-c-tooltip", `on`.toUpperCase())
}else{
set_on_off.setAttribute("data-c-tooltip", `off`.toUpperCase())
}
}


function check_on_off(){
function check_on_off() {
let on_off = JSON.parse(localStorage.getItem("setting_value")).work;
if (on_off) {
on_off_icon.style.fill = '#adadad'
// on_off_icon.setAttribute("fill", "#1db128 !important;")
let set_off = JSON.parse(localStorage.getItem("setting_value"))
set_off.work = false;
json_data.work = false;
localStorage.setItem("setting_value", JSON.stringify(set_off))
set_on_off_tooltip()
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
func: post_on_off,
args: [json_data]
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = tabs[0].url;
if (on_off && url.includes('fu.edunext.vn/')) {
on_off_icon.style.fill = '#adadad'
// on_off_icon.setAttribute("fill", "#1db128 !important;")
let set_off = JSON.parse(localStorage.getItem("setting_value"))
set_off.work = false;
json_data.work = false;
localStorage.setItem("setting_value", JSON.stringify(set_off))


// handleAlarm()


// chrome.action.setIcon({
// path: {
// '128': '../assets/image.png'
// }
// });


set_on_off_tooltip()
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
func: post_on_off,
args: [json_data]
});
});
});


} else if (!on_off && url.includes('fu.edunext.vn/')) {
on_off_icon.style.fill = '#1db128'
// on_off_icon.setAttribute("fill", "#f67412 !important;");
let set_on = JSON.parse(localStorage.getItem("setting_value"))
set_on.work = true;
json_data.work = true;
localStorage.setItem("setting_value", JSON.stringify(set_on))

} else if (!on_off) {
on_off_icon.style.fill = '#1db128'
// on_off_icon.setAttribute("fill", "#f67412 !important;");
let set_on = JSON.parse(localStorage.getItem("setting_value"))
set_on.work = true;
json_data.work = true;
localStorage.setItem("setting_value", JSON.stringify(set_on))
set_on_off_tooltip()
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
func: post_on_off,
args: [json_data]



chrome.action.setIcon({
path: {
'128': '../assets/logoauto.png'
}
});
});

set_on_off_tooltip()
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
func: post_on_off,
args: [json_data]
});
});


}

});

}
}

//detec on off button
on_off_icon.addEventListener('click', function () {
check_on_off()
check_on_off()
})


Expand Down Expand Up @@ -127,7 +172,7 @@ document.addEventListener("DOMContentLoaded", function () {
json_data.work = load_on_off;
set_on_off_tooltip()
} else if (!load_on_off) {
on_off_icon.style.fill = '#adadad'
on_off_icon.style.fill = '#adadad'
set_on_off_tooltip()
json_data.work = load_on_off;
}
Expand Down
Loading

0 comments on commit bbc6ffa

Please sign in to comment.