Browse Source

Tips that only show up 5 fives

Reddo 5 years ago
parent
commit
8934ac600b
1 changed files with 20 additions and 0 deletions
  1. 20 0
      app/Elements/Classes/Say/SayProtip.ts

+ 20 - 0
app/Elements/Classes/Say/SayProtip.ts

@@ -0,0 +1,20 @@
+/// <reference path="../Say.ts" />
+class SayProtip extends Say {
+    private static tipCounter = {};
+
+    public async getPureElements () : Promise<Array<Element | Text>> {
+        let paragraphs = await this.getParagraphs();
+        let elements = paragraphs.length == 1 ? paragraphs[0] : Array.prototype.concat.apply([], paragraphs);
+        let span = document.createElement("span");
+        span.classList.add("protip");
+        elements.forEach((element) => {
+            span.appendChild(element);
+        });
+        SayProtip.tipCounter[span.innerText] = SayProtip.tipCounter[span.innerText] == undefined ? 1 : SayProtip.tipCounter[span.innerText] + 1;
+        if (SayProtip.tipCounter[span.innerText] <= 5) {
+            return [span];
+        } else {
+            return [];
+        }
+    }
+}