Skip to content

Commit

Permalink
Add option "ignore countToAverageFlag" , fix form hidding
Browse files Browse the repository at this point in the history
  • Loading branch information
KGrzeg committed Jan 6, 2018
1 parent 9974f8b commit 72660e8
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 399 deletions.
2 changes: 1 addition & 1 deletion dist/bookmarklet.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/floating.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div id="AverageFloating"><table class="decorated form center"><thead><tr><td id="avHide" colspan="2" title="Ukryj panel wprowadzania ocen">Dodaj ocenę</td></tr></thead><tbody><tr class="line1"><th>Przedmiot</th><td><select id="avSubject" tabindex="0" class="left"></select></td></tr><tr class="line0"><th>Semestr</th><td><select id="avSemester" tabindex="1" class="small left"><option value="0" selected="1">1</option><option value="1">2</option></select></td></tr><tr class="line1"><th>Ocena</th><td><select name="" id="avRating" class="small left" tabindex="2"><option value="0" selected="0">0</option><option value="0.75" selected="0">1-</option><option value="1" selected="0">1</option><option value="1.5" selected="0">1+</option><option value="1.75" selected="0">2-</option><option value="2" selected="0">2</option><option value="2.5" selected="0">2+</option><option value="2.75" selected="0">3-</option><option value="3" selected="0">3</option><option value="3.5" selected="0">3+</option><option value="3.75" selected="0">4-</option><option value="4" selected="0">4</option><option value="4.5" selected="0">4+</option><option value="4.75" selected="0">5-</option><option value="5" selected="1">5</option><option value="5.5" selected="0">5+</option><option value="5.75" selected="0">6-</option><option value="6" selected="0">6</option><option value="6.5" selected="0">6+</option></select></td></tr><tr class="line0"><th>Waga</th><td><input id="avWeight" type="number" tabindex="3" value="1" class="left"></td></tr></tbody><tfoot><tr><td colspan="2"><button id="avSubmit" tabindex="30" class="small ui-button ui-widget ui-state-default ui-corner-all">Dodaj</button> <button id="avReset" tabindex="31" class="small ui-button ui-widget ui-state-default ui-corner-all">Wyczyść</button> <button id="avNormalize" tabindex="32" class="small ui-button ui-widget ui-state-default ui-corner-all">Ujednolicenie</button></td></tr></tfoot></table></div>
<div id="AverageFloating"><table class="decorated form center"><thead><tr><td id="avHide" colspan="2" title="Ukryj panel wprowadzania ocen">Dodaj ocenę</td></tr></thead><tbody><tr class="line1"><th>Przedmiot</th><td><select id="avSubject" tabindex="0" class="left"></select></td></tr><tr class="line0"><th>Semestr</th><td><select id="avSemester" tabindex="1" class="small left"><option value="0" selected="1">1</option><option value="1">2</option></select></td></tr><tr class="line1"><th>Ocena</th><td><select name="" id="avRating" class="small left" tabindex="2"><option value="0" selected="0">0</option><option value="0.75" selected="0">1-</option><option value="1" selected="0">1</option><option value="1.5" selected="0">1+</option><option value="1.75" selected="0">2-</option><option value="2" selected="0">2</option><option value="2.5" selected="0">2+</option><option value="2.75" selected="0">3-</option><option value="3" selected="0">3</option><option value="3.5" selected="0">3+</option><option value="3.75" selected="0">4-</option><option value="4" selected="0">4</option><option value="4.5" selected="0">4+</option><option value="4.75" selected="0">5-</option><option value="5" selected="1">5</option><option value="5.5" selected="0">5+</option><option value="5.75" selected="0">6-</option><option value="6" selected="0">6</option><option value="6.5" selected="0">6+</option></select></td></tr><tr class="line0"><th>Waga</th><td><input id="avWeight" type="number" tabindex="3" value="1" class="left"></td></tr><tr class="line1"><th title="Liczy oceny z informacją 'Licz do średniej: nie' jako oceny z wagą 1">Licz wszystkie oceny do średniej</th><td><input id="avIgnoreCountToAverage" type="checkbox" tabindex="4" class="styled"></td></tr></tbody><tfoot><tr><td colspan="2"><button id="avSubmit" tabindex="30" class="small ui-button ui-widget ui-state-default ui-corner-all">Dodaj</button> <button id="avReset" tabindex="31" class="small ui-button ui-widget ui-state-default ui-corner-all">Wyczyść</button> <button id="avNormalize" tabindex="32" class="small ui-button ui-widget ui-state-default ui-corner-all">Ujednolicenie</button></td></tr></tfoot></table></div>
54 changes: 40 additions & 14 deletions dist/tamper.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
// @description Automatyczne liczenie średniej ocen na portalu synergia.librus.pl z uwzględnieniem wag dla uczniów szkół, które wyłączyły tę funkcjonalność
// @author Grzegorz Kupczyk

// @version 0.1
// @version 0.2
// @downloadURL https://raw.githubusercontent.com/GrzegorzKu/avgsynergia/master/dist/tamper.user.js
// @updateURL https://raw.githubusercontent.com/GrzegorzKu/avgsynergia/master/dist/tamper.user.js
// @supportURL https://github.com/GrzegorzKu/avgsynergia/issues

// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @icon64 https://github.com/GrzegorzKu/avgsynergia/tree/master/images/logo.png
// @icon64URL https://github.com/GrzegorzKu/avgsynergia/tree/master/images/logo.png
// @icon64 https://raw.githubusercontent.com/GrzegorzKu/avgsynergia/master/images/logo.png
// @icon64URL https://raw.githubusercontent.com/GrzegorzKu/avgsynergia/master/images/logo.png

// @resource floating https://raw.githubusercontent.com/GrzegorzKu/avgsynergia/master/dist/floating.html
// @resource css https://raw.githubusercontent.com/GrzegorzKu/avgsynergia/master/dist/style.css
Expand Down Expand Up @@ -44,7 +44,6 @@ var inline_src = (<><![CDATA[
appendAverage(wavg) {
this._rawValues += wavg.rawValue
this._weights += wavg.weights
//this.add(wavg.rawValue, wavg.weights)
}
reset() {
this._rawValues = 0
Expand Down Expand Up @@ -75,18 +74,17 @@ var inline_src = (<><![CDATA[
this._countable = true
this._countToAverage = this.parseCountToAverage(this._$aElement.attr("title"))
this._weight = this.parseWeight(this._$aElement.attr("title"))
if (this._countToAverage !== null && this._weight !== null)
this._countable = true
else
this._countable = false

if (this._weight === null)
this._weight = Mark.defualt_weight
} else {
this._countable = false
this._countToAverage = false
this._weight = 0
}
} else {
this._value = grade
this._weight = weight
this._weight = Math.min(1, weight) //weight can't be smaller than 1
this._countToAverage = true
this._countable = true
this._$boxElement = this._generateBox()
Expand Down Expand Up @@ -213,6 +211,7 @@ var inline_src = (<><![CDATA[
}
}
}
Mark.defualt_weight = 1
class Subject {
constructor(row) {
let cells = $(row).children()
Expand All @@ -232,6 +231,8 @@ var inline_src = (<><![CDATA[
this._average_cell_II = cells[Subject.AvgIICell]
this._average_cell_III = cells[Subject.AvgIIICell]

this._ignore_count_to_average_flag = false

this._readMarks()
this.updateAverages()
}
Expand All @@ -244,20 +245,25 @@ var inline_src = (<><![CDATA[
let marks_II = $.merge($.merge([], this._marks_II), this._marks_extra_II)

$.each(marks_I, (i, m) => {
if (m.countable) avg_I.add(m.value, m.weight)
if (m.countable && (m.countToAverage || this._ignore_count_to_average_flag)) avg_I.add(m.value, m.weight)
})
$.each(marks_II, (i, m) => {
if (m.countable) avg_II.add(m.value, m.weight)
if (m.countable && (m.countToAverage || this._ignore_count_to_average_flag)) avg_II.add(m.value, m.weight)
})


if (avg_I.value !== 0)
$(this._average_cell_I).text(avg_I.value.toFixed(2))
else
$(this._average_cell_I).text("")
if (avg_II.value !== 0) {
$(this._average_cell_II).text(avg_II.value.toFixed(2))

avg_I.appendAverage(avg_II)
$(this._average_cell_III).text(avg_I.value.toFixed(2))
} else {
$(this._average_cell_II).text("")
$(this._average_cell_III).text("")
}
}
addMark(mark, semester) {
Expand Down Expand Up @@ -309,14 +315,22 @@ var inline_src = (<><![CDATA[
return this._marks_II
}

set ignore_count_to_average_flag(v) {
let t = this._ignore_count_to_average_flag
this._ignore_count_to_average_flag = v

if (t !== v)
this.updateAverages()
}

/* read table's header, and calculate the offsets of cells
argument thead:jquery object (last row of thead) */
static calculate_cells(thead) {
if (Subject.TheadProcessed)
return

thead.children().each((i, e) => {
i += 2 //the header have 2 rows with spaned cells; second is offset by 2
i += 2 //the header have 2 rows with spaned cells; second is offset by 2
switch ($(e).text()) {
case "Oceny bieżące":
{
Expand Down Expand Up @@ -387,6 +401,12 @@ Subject.TheadProcessed = false
$('.decorated.stretch:visible>tbody')
.toggleClass("markNormalize")
}
ignoreCountToAverage() {
let val = $("#avIgnoreCountToAverage").prop("checked")
this._subjects.forEach((e, i) => {
e.ignore_count_to_average_flag = val;
})
}

_readSubjects() {
let thead = $('.decorated.stretch:visible>thead>tr:last')
Expand Down Expand Up @@ -420,6 +440,7 @@ Subject.TheadProcessed = false
$("#avSubmit").click(this.addMark.bind(this))
$("#avReset").click(this.clearMarks.bind(this))
$("#avNormalize").click(this.normalize.bind(this))
$("#avIgnoreCountToAverage").click(this.ignoreCountToAverage.bind(this))
}
_attachDisplay() {
this._pane_hidded = false
Expand All @@ -435,8 +456,13 @@ Subject.TheadProcessed = false
//hide
let height =
$("#AverageFloating").height() -
($("#avHide").height() + parseInt($("#AverageFloating table").css("margin-top")) - 5)

(
$("#avHide").height() +
parseInt($("#avHide").css("padding-top")) +
parseInt($("#avHide").css("padding-bottom")) +
parseInt($("#AverageFloating table").css("margin-top"))
)

$("#AverageFloating")
.animate({
bottom: -height
Expand Down
Loading

0 comments on commit 72660e8

Please sign in to comment.