Skip to content

Instantly share code, notes, and snippets.

@gMan1990
Last active December 26, 2019 10:56
Show Gist options
  • Save gMan1990/44f7a7ba1a6b9c458b6b144640071b6f to your computer and use it in GitHub Desktop.
Save gMan1990/44f7a7ba1a6b9c458b6b144640071b6f to your computer and use it in GitHub Desktop.
jQuery(function ($) {
    var result = new Map(),
    processor = function (ele) {
        $("div.sms-number-list.row", ele).each(function (i, e) {
            var key = e.querySelector("div>a").href,
            val = result.get(key),
            text = $.text(e.querySelector("div>h3"));
            if (val) {
                val.push(text);
            } else {
                result.set(key, [text]);
            }
        });
    },
    $pages = $("ul.pagination>li"),
    min = Number($.text($pages[1])),
    max = $.text($pages[$pages.length - 2]),
    active = $pages.filter(".active").text(),
    _continue = true;
    for (var i = min; _continue && i <= max; i++) {
        if (i == active) {
            processor(document);
        } else {
            $.ajax({
                async: false,
                url: "https://www.materialtools.com/?page=" + i,
                success: function (res) {
                    processor(res);
                },
                error: function () {
                    _continue = false;
                    console.error(arguments);
                }
            });
        }
    }
    _continue && console.log(JSON.stringify([...result]));
});
[
    [
        "https://www.pdflibr.com/SMSContent/1",
        [
            "+8619965412404",
            "+12123630317"
        ]
    ]
    /* , ... */
]

https://www.pdflibr.com/ https://www.materialtools.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment