Prechádzať zdrojové kódy

Tips that only show up 5 fives

Reddo 5 rokov pred
rodič
commit
8934ac600b
1 zmenil súbory, kde vykonal 20 pridanie a 0 odobranie
  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 [];
+        }
+    }
+}