Skip to content

Commit

Permalink
Merge pull request #25 from nmanumr/fixes/ext-detection
Browse files Browse the repository at this point in the history
fixes duplicate event listeners
  • Loading branch information
nmanumr authored Oct 16, 2022
2 parents 5df855e + 48c5acf commit d2a58c2
Show file tree
Hide file tree
Showing 8 changed files with 3,202 additions and 3,615 deletions.
6,711 changes: 3,144 additions & 3,567 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@stitches/react": "^0.2.4",
"classnames": "^2.3.1",
"firebase": "^9.0.0-beta.7",
"firebase": "^9.12.1",
"preact": "^10.5.14",
"react": "^17.0.2",
"react-dom": "^17.0.2"
Expand Down
68 changes: 34 additions & 34 deletions src/consts.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"name": "Quiz Sliver",
"description": "COMSATS hybrid quiz solver",
"version": "<%EXT_VERSION%>",
"iconsDir": "icons",
"services": [
"cookies",
"storage",
"webRequest",
"webRequestBlocking",
"declarativeContent"
],
"portalUrls": [
"https://cuonline.cuilahore.edu.pk:8091/*",
"http://cuonline.cuilahore.edu.pk:8091/*",
"https://cms.comsats.edu.pk:8083/*",
"http://cms.comsats.edu.pk:8083/*",
"https://swl-cms.comsats.edu.pk:8082/*",
"http://swl-cms.comsats.edu.pk:8082/*",
"https://cuonline.ciitwah.edu.pk:8090/*",
"http://cuonline.ciitwah.edu.pk:8090/*",
"https://cuonline.cuiwah.edu.pk:8095/*",
"http://cuonline.cuiwah.edu.pk:8095/*",
"https://atk-cms.comsats.edu.pk:8090/*",
"http://atk-cms.comsats.edu.pk:8090/*",
"https://vhr-cms.comsats.edu.pk:8089/*",
"http://vhr-cms.comsats.edu.pk:8089/*"
],
"externalUrls": [
"https://cdnjs.cloudflare.com/*",
"https://ajax.googleapis.com/*",
"https://www.gstatic.com/*"
],
"firebaseConfig": "<%FIREBASE_CONFIG%>"
}
"name": "Quiz Sliver",
"description": "COMSATS hybrid quiz solver",
"version": "<%EXT_VERSION%>",
"iconsDir": "icons",
"services": [
"cookies",
"storage",
"webRequest",
"declarativeContent"
],
"portalUrls": [
"https://cuonline.cuilahore.edu.pk:8091/",
"http://cuonline.cuilahore.edu.pk:8091/",
"https://cms.comsats.edu.pk:8083/",
"http://cms.comsats.edu.pk:8083/",
"https://swl-cms.comsats.edu.pk:8082/",
"http://swl-cms.comsats.edu.pk:8082/",
"https://cuonline.ciitwah.edu.pk:8090/",
"http://cuonline.ciitwah.edu.pk:8090/",
"https://cuonline.cuiwah.edu.pk:8095/",
"http://cuonline.cuiwah.edu.pk:8095/",
"https://atk-cms.comsats.edu.pk:8090/",
"http://atk-cms.comsats.edu.pk:8090/",
"https://vhr-cms.comsats.edu.pk:8089/",
"http://vhr-cms.comsats.edu.pk:8089/"
],
"externalUrls": [
"https://cdnjs.cloudflare.com/",
"https://ajax.googleapis.com/",
"https://www.gstatic.com/",
"https://cdn.firebase.com/"
],
"firebaseConfig": "<%FIREBASE_CONFIG%>"
}
7 changes: 4 additions & 3 deletions src/handlers/courses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {IHandler} from "./base";
import {recreateNode} from "../utils";

export class CoursesPage implements IHandler {
async handle(doc: Document) {
Expand All @@ -9,10 +10,10 @@ export class CoursesPage implements IHandler {
.getAttribute('onclick')
.match(/\/Courses\/SetCourse\/(\d+)/)[1];

trs[i].setAttribute('onclick', "");
trs[i].onclick = () => {
trs[i].removeAttribute('onclick');
recreateNode(trs[i]).addEventListener('click', () => {
this.onCourseOpened(id, trs[i].querySelector('td').innerText.trim())
};
});
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/handlers/mcq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {_app$} from "../@types";
import {IHandler} from "./base";
import {h, render} from 'preact';
import {hashCode} from "../utils";
import {recreateNode} from "../utils";
import mcqParser from "../parsers/mcq";
import mcqService from "../services/mcq";
import {ParsedMcqWithAnswer} from "../types";
import userInfoParser, {IUserInfo} from "../parsers/userInfo";
import courseDetailsParser, {ICourseDetail} from "../parsers/courseDetails";
import Loader, {LoaderState, Globals as LoaderGlobals} from "../components/Loader";
import Loader, {LoaderState} from "../components/Loader";

export class McqPage implements IHandler {
private mcqFound = false;
Expand Down Expand Up @@ -58,8 +59,9 @@ export class McqPage implements IHandler {
}

bindOnMcqSubmitted() {
document.querySelector(`.submit_btn`).setAttribute('onclick', '');
document.querySelector(`.submit_btn`).addEventListener("click", this.onMcqSubmit.bind(this));
let element = document.querySelector(`.submit_btn`);
element.removeAttribute('onclick');
recreateNode(element).addEventListener("click", this.onMcqSubmit.bind(this));
}

bindOnOptionSelected() {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ export function hashCode(input: string): number {
}
return hash;
}

export function recreateNode(el: Element): Element {
var newEl = el.cloneNode(false) as Element;
while (el.hasChildNodes()) newEl.appendChild(el.firstChild);
el.parentNode.replaceChild(newEl, el);

return newEl;
}
11 changes: 5 additions & 6 deletions tools/build-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ export default function writeManifest(outDir) {
icons: Object.fromEntries([16, 48, 128].map((s) => [s, `${consts.iconsDir}/icon${s}.png`])),
permissions: [
...consts.services,
...consts.portalUrls,
...consts.externalUrls,
],
host_permissions: [
'https://cdn.firebase.com',
'https://*.firebaseio.com',
'https://*.gstatic.com'
...consts.portalUrls,
...consts.externalUrls,
],
content_scripts: [{
matches: [...consts.portalUrls],
matches: [
...consts.portalUrls.map(e => e + '*')
],
js: ['sliver.js']
}],
}
Expand Down
2 changes: 1 addition & 1 deletion tools/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from "fs-extra";
import fs from "fs-extra";
import dotenv from 'dotenv';

import rollupBundle from './rollup.js'
Expand Down

0 comments on commit d2a58c2

Please sign in to comment.