Scraper.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW12
  3. * https://github.com/wordpress-mobile/WordPress-iOS/blob/develop/WordPress/WordPressShareExtension/WordPressShare.js
  4. */
  5. var Scraper = function() {};
  6. Scraper.prototype = {
  7. run: function(arguments) {
  8. /* https://codeberg.org/mro/ShaarliGo/src/branch/develop/tpl/tools.html */
  9. const url = document.location.href; // not convinced baseURI is a better choice
  10. /* scrape */
  11. /* precedence like comb.go#L54 */
  12. const tit = document.title
  13. ?? document.querySelector('meta[name=\'title\']')?.content
  14. ?? document.querySelector('meta[property=\'og:title\']')?.content
  15. ?? '';
  16. const tgs = document.querySelector('meta[name=\'keywords\']')?.content
  17. ?? document.querySelector('meta[name=\'news_keywords\']')?.content
  18. ?? '';
  19. const con = document.getSelection()?.toString()
  20. || document.querySelector('meta[name=\'description\']')?.content
  21. || '';
  22. const img = document.querySelector('meta[property=\'og:image\']')?.content
  23. ?? '';
  24. arguments.completionFunction({
  25. "url": url,
  26. "title": tit,
  27. "description": con,
  28. "keywords": tgs,
  29. "image": img,
  30. });
  31. }
  32. };
  33. var ExtensionPreprocessingJS = new Scraper;