Quellcode durchsuchen

Tips that only show up 5 fives

Reddo vor 5 Jahren
Ursprung
Commit
8934ac600b
1 geänderte Dateien mit 20 neuen und 0 gelöschten Zeilen
  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 [];
+        }
+    }
+}