4

[Chrome Extension] Show Instagram Id on User Page

 2 years ago
source link: http://siongui.github.io/2018/02/22/crx-show-ig-id-on-user-page/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[Chrome Extension] Show Instagram Id on User Page

Updated: April 13, 2018

[Update]: Now Instagram bans access to /?__a=1 URL, so this extension cannot work now. See my new way to do this [2].

A Chrome extension to help you show Instagram id on the user page.

manifest json:

manifest.json | repository | view raw

{
  "manifest_version": 2,

  "name": "showigid",
  "description" : "Show Instagram Id on user page",
  "version": "0.1",

  "background": {
      "scripts": ["eventPage.js"]
  },

  "content_scripts": [
    {
      "matches": ["https://www.instagram.com/*"],
      "js": ["showid.js"]
    }
  ],

  "permissions": [
    "https://www.instagram.com/*",
    "tabs"
  ]
}

background.js:

eventPage.js | repository | view raw

var reUrlUser = /^https:\/\/www\.instagram\.com\/([a-z0-9_.]+)\/$/;

function sendMsg(id, url) {
  chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
    chrome.tabs.sendMessage(
      tabs[0].id,
      {id: id, url: url}
    );
  });
}

function getId(url) {
  var jsonUrl = url + "?__a=1";
  var xhr = new XMLHttpRequest();
  xhr.open("GET", jsonUrl, true);
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
      // JSON.parse does not evaluate the attacker's scripts.
      var resp = JSON.parse(xhr.responseText);
      sendMsg(resp["user"]["id"], jsonUrl);
    }
  }
  xhr.send();
}

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
  if (changeInfo.hasOwnProperty('url')) {

    // check if URL is user page
    var result = changeInfo.url.match(reUrlUser);
    if (result) {
      getId(changeInfo.url);
    }
  }
});

showid.js:

showid.js | repository | view raw

function showId(elm, id, url) {
  var link = document.createElement("a");
  link.setAttribute("href", url);
  link.setAttribute("target", "_blank");
  link.setAttribute("class", "_fd86t");
  link.appendChild(document.createTextNode(id));

  elm.appendChild(document.createElement("br"));
  elm.appendChild(link);
}

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {

    // wait page to be loaded
    var timerId = setInterval(function() {
      var n = document.querySelector("section._o6mpc");
      if (n != null) {
        showId(n, request.id, request.url);
        clearInterval(timerId);
      }
    }, 500);
  });

References:

[1]GitHub - siongui/fbidcrx: Try to find Facebook Id via Chrome Extension


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK