SayProtip.ts 802 B

1234567891011121314151617181920
  1. /// <reference path="../Say.ts" />
  2. class SayProtip extends Say {
  3. private static tipCounter = {};
  4. public async getPureElements () : Promise<Array<Element | Text>> {
  5. let paragraphs = await this.getParagraphs();
  6. let elements = paragraphs.length == 1 ? paragraphs[0] : Array.prototype.concat.apply([], paragraphs);
  7. let span = document.createElement("span");
  8. span.classList.add("protip");
  9. elements.forEach((element) => {
  10. span.appendChild(element);
  11. });
  12. SayProtip.tipCounter[span.innerText] = SayProtip.tipCounter[span.innerText] == undefined ? 1 : SayProtip.tipCounter[span.innerText] + 1;
  13. if (SayProtip.tipCounter[span.innerText] <= 5) {
  14. return [span];
  15. } else {
  16. return [];
  17. }
  18. }
  19. }