If you can’t leave a comment, but really want, then you can

    Yes, it was precisely this problem that I encountered when I visited the next Landing page, which allegedly sold first-class goods to me. But after the courier’s visit, you understand that you’ve been divorced, and you are not able to leave a review or somehow warn the others. At this moment, the idea came up of the extension for the browser, which would allow you to leave comments, notes, reviews or read others, right on the site you are visiting.



    Name to all this CommentAll . If still interesting - I ask under kat. Even if you are not interested , still look under the cut, it may be too early to draw conclusions, and leave your angry comment is always welcome.

    How was it


    I just chose a gift for my wife, having stumbled upon a site selling a night projector, projecting a star galaxy onto the ceiling. I was shocked - his presentation on the site bought me. Returning to the site after I twisted in my hands what the courier had brought and not finding any similarities with what was advertised on the site, I saw only static comments and a form that sends my review to nowhere.

    It was possible to participate only in a mocking poll, here it is:
    • We are delighted, now we sleep like in a fairy tale
    • An original gift, thank you!
    • Excellent that work around the clock
    • Be sure to buy!
    • I ordered it, I was satisfied, thanks a lot.

    As a result, it touched me all, and the goal appeared so simply not to leave it. Expansion ideaCommentall is to provide an opportunity for an Internet audience to communicate directly on sites, without going anywhere, to warn other network users about the possible placement of dangerous content, sometimes not accurate or even false information, i.e. even where the author himself did not provide for the possibility of commenting or found it unnecessary.

    Instead of a thousand words about the principle of the extension itself, I suggest watching a short minute video:



    A bit about the technical side of the project


    The extension is written for browsers on the WebKit engine, such as Google Chrome (+ its derivatives Yandex.Browser , Amigo , etc.), Opera has a separate release, because Opera has its own store of extensions, and different from the rest of Firefox , for everything the rest is not yet, under IE I don’t even know if it’s worth it.

    The main difficulty that I had to face is that modern browsers do not allow cross-domain requests. Moreover, for extensions, most of the methods found on the network, such as JSONP, CORS, did not work or could not be applied. The solution came from the extension itself - in browsers on WebKit they consist of the "main" part and the so-called "background". And it turns out that all requests that pass in the background are passed by the browser. It remains to tie it all together. It turns out this chain:



    i.e. all requests needed a wrapper in the form of a function that took request parameters in background'e, formed the request itself and, upon completion, called CallBack. Found the only working solution on the Internet - from romannurik and slightly modified it (for processing POST requests).

    part of Background - Xhrproxy.js
    var XHR_PROXY_PORT_NAME_ = 'XHRProxy_';
    function setupXHRProxy() {
         chrome.extension.onConnect.addListener(function(port) {
              if (port.name != XHR_PROXY_PORT_NAME_)
              return;
              port.onMessage.addListener(function(xhrOptions) {
                   var xhr = new XMLHttpRequest();
                   xhr.open(xhrOptions.method || "GET", xhrOptions.url, true);
                   if ( xhrOptions.method=='POST' ) {
                       xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                        xhr.setRequestHeader("Content-length", xhrOptions.params.length);
                        xhr.setRequestHeader("Connection", "close");
                   }
                   xhr.onreadystatechange = function() {
                        if (this.readyState == 4) {
                             port.postMessage({
                                  status: this.status,
                                  data: this.responseText,
                                  xhr: xhr,
                                  url: xhrOptions.url,
                                  post_data:xhrOptions.params
                             });
                        }
                   }
                   if ( xhrOptions.method=='POST' ) {
                        xhr.send(xhrOptions.params);
                   }else{
                        xhr.send();
                   }
              });
         });
    }
    function proxyXHR(xhrOptions) {
         xhrOptions = xhrOptions || {};
         xhrOptions.onComplete = xhrOptions.onComplete || function(){};
         var port = chrome.extension.connect({name: XHR_PROXY_PORT_NAME_});
         port.onMessage.addListener(function(msg) {
              xhrOptions.onComplete(msg.status, msg.data, msg.xhr, msg.url, msg.post_data);          
         });
         port.postMessage(xhrOptions);
    }
    setupXHRProxy();
    


    An example of a call from the extension itself:
    proxyXHR({
        method      : 'POST',
        url         : url,
        params      : post_data,
        onComplete  : CommentAll.loadComment
    });  
    


    and in manifest.json file
      "background": {
              "scripts": ["includes/xhrproxy.js"]
        }
    


    If anyone has a better solution - I will be glad to listen, adequate criticism is only welcome. If the topic of extension development is interesting, then I will write a sequel.

    PS


    For the convenience of commenting, social authorization has been introduced for VKontakte, Facebook and Twitter. But you can leave a comment anonymously. Yes, of course there is a slight limitation due to the small audience of the extension so far - comments and notes will be visible only to those who also have the extension. In the future, it is planned to expand the expansion functionality (sorry for the tautology), but in fact, other possibilities are already open before it.

    Here are just sample application options:
    • When viewing ads (for example, selling a car or apartment), leaving a note after making a call or inspecting an object (or seeing an existing review)
    • When two or more people work on the same content, editing or discussing it on the spot so as not to get confused.
    • When it is necessary not to advertise the fact of correspondence, while communicating on non-popular sites.
    • Use for quests, revelations, and maybe something else.
    I just wanted to add that there is no advertising or other monetization in the extension. I almost forgot to warn, the self-written filter of obscene language works, converting the mat into synonyms, and sometimes even into antonyms.

    And exclusively for those who read the article from the very beginning, this exceptional survey.

    Only registered users can participate in the survey. Please come in.

    What do you think of the CommentAll extension:

    • 13.5% I am delighted, now I am commenting on everything 52
    • 43.3% Original extension, thanks! 166
    • 13% Excellent, that works without ads 50
    • 8.8% Be sure to add extension 34
    • 21.1% Super. Now I’ll install and write everything I think about you 81

    Also popular now: