BlogsMarks - Add to BlogsMarks (Userscript)

Add a new Mark to BlogMarks.net by Selecting a piece of text and clicking the BlogMarks's icon which appear after the selection

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name BlogsMarks - Add to BlogsMarks (Userscript)
  3. // @namespace https://blogmarks.net
  4. // @version 0.2
  5. // @description Add a new Mark to BlogMarks.net by Selecting a piece of text and clicking the BlogMarks's icon which appear after the selection
  6. // @author Decembre
  7. // @icon https://icons.iconarchive.com/icons/sicons/basic-round-social/48/blogmarks-icon.png
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var selectionIcon = null;
  15.  
  16. document.addEventListener('selectionchange', function() {
  17. if (selectionIcon) {
  18. selectionIcon.remove();
  19. selectionIcon = null;
  20. }
  21.  
  22. var selection = window.getSelection();
  23. if (selection.toString() !== '') {
  24. var range = selection.getRangeAt(0);
  25. var rect = range.getBoundingClientRect();
  26. selectionIcon = document.createElement('img');
  27. selectionIcon.src = 'https://icons.iconarchive.com/icons/sicons/basic-round-social/48/blogmarks-icon.png';
  28. selectionIcon.style.position = 'absolute';
  29. selectionIcon.style.top = (rect.top + window.scrollY) + 'px';
  30. selectionIcon.style.left = (rect.left + window.scrollX + rect.width) + 'px';
  31. selectionIcon.style.width = '32px';
  32. selectionIcon.style.height = '32px';
  33. selectionIcon.style.cursor = 'pointer';
  34. selectionIcon.style.zIndex = '1000';
  35. document.body.appendChild(selectionIcon);
  36.  
  37. selectionIcon.addEventListener('click', function() {
  38. var q = selection.toString();
  39. var r = document.referrer;
  40. void(open('http://blogmarks.net/my/marks,new?mini=1' +
  41. '&title=' + encodeURIComponent(document.title) +
  42. '&url=' + encodeURIComponent(location.href) +
  43. '&summary=' + encodeURIComponent(q) +
  44. '&via=' + encodeURIComponent(r),
  45. 'blogmarks', 'location=no,toolbar=no,scrollbars=yes,width=350,height=450,status=no'));
  46. });
  47. }
  48. });
  49. })();