actor.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function autoButtons(elms) {
  2. for (var i = elms.length - 1; i >= 0 ; i--) {
  3. const elm = elms[i];
  4. // https://stackoverflow.com/a/26946264/349514
  5. elm.addEventListener('input', function (evt) {
  6. this.form.submit();
  7. });
  8. }
  9. }
  10. document.documentElement.classList.add('script-active');
  11. document.documentElement.classList.remove('script-inactive');
  12. const xml_base_pub = document.documentElement.getAttribute("data-xml-base-pub");
  13. // make http and geo URIs (RFC 5870) clickable + microformat
  14. function clickableTextLinks(elmsRendered) {
  15. console.log('actor.js:clickableTextLinks');
  16. for (var i = elmsRendered.length - 1; i >= 0 ; i--) {
  17. const elm = elmsRendered[i];
  18. elm.innerHTML = elm.innerHTML
  19. .replace(/(https?:\/\/([^ \t\r\n"'<]+[^ \t\r\n"'<.,;:)]))/gi, '<a rel="noreferrer" title="WWW" class="http" href="$1">$2</a>')
  20. // https://alanstorm.com/url_regex_explained/ \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
  21. // .replace(/\b(([\w-]+:\/\/?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/gi, '<a rel="noreferrer" class="http" href="$1">$1</a>')
  22. .replace(/@([a-z0-9._-]+)@([a-z0-9._-]+)/gi, '<a rel="webfinger" title="Webfinger" class="http" href="https://$2/.well-known/webfinger?resource=acct:$1@$2">@$1@$2</a>')
  23. .replace(/geo:(-?\d+.\d+),(-?\d+.\d+)(\?z=(\d+))?/gi, '<a class="geo" href="https://opentopomap.org/#marker=12/$1/$2" title="zoom=$4">geo:<span class="latitude">$1</span>,<span class="longitude">$2</span>$3</a>')
  24. .replace(/(#RFC(\d+)(#\S*[0-9a-z])?)/gi, '<a class="rfc" href="https://tools.ietf.org/html/rfc$2$3" title="RFC $2">$1</a>')
  25. .replace(/(urn:ietf:rfc:(\d+)(#\S*[0-9a-z])?)/gi, '<a class="rfc" href="https://tools.ietf.org/html/rfc$2$3" title="RFC $2">$1</a>')
  26. .replace(/(urn:isbn:([0-9-]+)(#\S*[0-9a-z])?)/gi, '<a class="isbn" href="https://de.wikipedia.org/wiki/Spezial:ISBN-Suche?isbn=$2" title="ISBN $2">$1</a>')
  27. .replace(/(urn:ean:([0-9-]+)(#\S*[0-9a-z])?)/gi, '<a class="ean" href="https://www.ean-suche.de/?q=$2" title="EAN $2">$1</a>')
  28. .replace(/(CVE-[0-9-]+-[0-9]+)/gi, '<a class="cve" href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=$1">$1</a>');
  29. }
  30. }
  31. autoButtons(document.querySelectorAll(".btn input[type='checkbox']"));
  32. clickableTextLinks(document.getElementsByClassName('clickable'));