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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         BlogsMarks - Add to BlogsMarks (Userscript)
// @namespace    https://blogmarks.net
// @version      0.3
// @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
// @author       Decembre
// @icon         https://icons.iconarchive.com/icons/sicons/basic-round-social/48/blogmarks-icon.png
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var selectionIcon = null;

    document.addEventListener('selectionchange', function() {
        if (selectionIcon) {
            selectionIcon.remove();
            selectionIcon = null;
        }

        var selection = window.getSelection();
        if (selection.toString() !== '') {
            var range = selection.getRangeAt(0);
            var rect = range.getBoundingClientRect();
            selectionIcon = document.createElement('img');
            selectionIcon.src = 'https://icons.iconarchive.com/icons/sicons/basic-round-social/48/blogmarks-icon.png';
            selectionIcon.style.position = 'absolute';
            selectionIcon.style.top = (rect.top + window.scrollY) + 'px';
            selectionIcon.style.left = (rect.left + window.scrollX + rect.width) + 'px';
            selectionIcon.style.width = '32px';
            selectionIcon.style.height = '32px';
            selectionIcon.style.cursor = 'pointer';
            selectionIcon.style.zIndex = '1000';
            document.body.appendChild(selectionIcon);

            selectionIcon.addEventListener('click', function() {
                var q = selection.toString();
                var r = document.referrer;
                void(open('http://blogmarks.net/my/marks,new?mini=1' +
                    '&title=' + encodeURIComponent(document.title) +
                    '&url=' + encodeURIComponent(location.href) +
                    '&summary=' + encodeURIComponent(q) +
                    '&via=' + encodeURIComponent(r),
                    'blogmarks', 'location=no,toolbar=no,scrollbars=yes,width=350,height=450,status=no'));
            });
        }
    });
})();