npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

social-media-scanner

v0.3.0

Published

Retrieve links to social media from websites

Downloads

14

Readme

social-media-scanner

Scan websites for links to social media

Support


Social Media Scanner supports the following links:

  • Facebook
  • Google +
  • Twitter
  • Linkedin
  • Instagram
  • Pinterest
  • Reddit
  • Tumblr
  • VK

Installation


You can install Social Media Scanner through npm

npm install --save social-media-scanner

Usage


Setup

Start by requiring the node module

var socialMediaScanner = require("social-media-scanner");

Then you can start scanning a website using .scan(url);. This will create a new scanner object for this website.

var site1 = socialMediaScanner.scan("http://example.com");

Events

Social Media Scanner has four events: pageStart, pageDone, done and error.
You can set callbacks for these events with:

site1.on("error", function (err) {});

pageStart

This event is called at the start of a scan of a page.
The callback for this event has a page object parameter and a skip method.
The page object has the following properties:

  • url: The url of the page which just started scanning
  • key: A unique key for this page
  • found: an object with a list of all found links (links: string[]) and a list of all found media(media: string[]). page.found.media and page.found.links are just empty arrays at the start of the scan

When the skip method is called the page won't be scanned

site1.on("pageStart", function (page, skip) {
  if (page.url === "http://example.com/example") {
    skip();
    return;
  }
  console.log("Started scanning: " + page.url);
});

pageDone

This event returns the same object as above except for page.found.media and page.found.links which now hold values

site1.on("pageDone", function (page) {
  console.log("Done scanning: " + page.url);
  console.log("Found media: " + page.found.media);
  console.log("Found links: " + page.found.links);
});

done

This event fires at the end of the scan and returns a list of all media found and all scanned pages

site1.on("done", function (media, pages) {
  console.log("Found: " + media); // Shows a string array with all found media
  console.log("Scanned pages: " + pages); // each page has the same structure as the pages in the previous events
});

error

This event fires everytime the scanner encounters an error.

site1.on("error", function (err) {
  console.log(err);
});

Properties

A scanner has 3 properties:

  • max: The max amount of pages to search through (default: 100).
  • interval: The amount of milliseconds between each page scan (default: 250).
  • skipExternalResources: Social Media Scanner loads external javascript files because some websites get their content from scripts (for example: React websites).
    Default: false
// skipExternalResources example
site1.on("pageStart", function (page) {
  if (page.url === "http://example.com/a-specific/path") {
    site1.skipExternalResources = false;
  } else {
    site1.skipExternalResources = true;
  }
});

methods

  • getMedia(): Returns a list of media to check for
  • addMedium(med: string[]|string): Add one medium or a list of media to the list of media which will be used to check urls
  • removeMedium(med: string[]|string): Remove one medium or a list of media from the list of media which will be used to check urls
  • blockURL(url: string): The URL passed to this method won't be scanned

Starting the scan

After everything is setup you can start the scan with:

site1.start();