Instagram Stories Opener

Opens the content from an instagram story in a new tab

目前为 2018-09-25 提交的版本。查看 最新版本

// ==UserScript==
// @name         Instagram Stories Opener
// @version      0.5
// @description  Opens the content from an instagram story in a new tab
// @author       jomifepe
// @icon         https://www.instagram.com/favicon.ico
// @require      https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
// @include      https://www.instagram.com/*
// @grant        GM_addStyle
// @namespace https://gf.qytechs.cn/users/192987
// ==/UserScript==

/* these values may change */
const C_STORY_CONTAINER = "lXJWB";
const C_STORY_MEDIA_CONTAINER = "qbCDp";

const C_BTN = "iso-btn";
const C_BTN_CONTAINER = "iso-container";

var b64icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAQAAABKfvVzAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAADdcAAA3XAUIom3gAAAAHdElNRQfiAxwDOBTFNFQBAAABKklEQVQ4y6WTvUoDQRSFvwkbxCqijY2okEIEixQpBMHKykIFC8H/yiew8Rl8i4ClCoJYWGkhaGXjrkmTbsUiTQoVf45Ndp1lZ8eIp7vnnnPvnBkG/gjjb2uAOcoW0fplnvaVRccAaIFZhnPqW3OkMa4Zz84o60RunAFoQm2bDDhgmSsOHad7BjBtrXFjb3jUi0Y8KUYV2hvQly77kH/qKTFIF33Id5MsHoMl30njdwoNlnw75SqaLDC45EnLYbDkW/lZOYMl3wRQTTW/4bQn3+jVoUK/YUqxPrSe1pGin26QD2wizVM15+7LDlykadIseswSbwzhgUpUeLWJO0nTHsOSpIa1XSsc06VR8PnqrGKom3t7xp66KkasxUw+AA0y4/iiADEP5p3/4BuEXi9gkPrfQgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxOC0wMy0yOFQwMzo1NjoyMCswMjowMO7sj9MAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTgtMDMtMjhUMDM6NTY6MjArMDI6MDCfsTdvAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAABJRU5ErkJggg==";
GM_addStyle(`.${C_BTN}{border:none;position:fixed;top:0;right:0;margin:20px;cursor:pointer;width:24px;height:24px;background-color:transparent;background-image:url(${b64icon})}`);

var body, button, buttonContainer;
/* triggered whenever a story is opened */
document.arrive(`.${C_STORY_CONTAINER}`, function() {
    createButton();
});

function createButton() {
    if (buttonExists()) {
        return;
    }

    buttonContainer = document.createElement("div");
    buttonContainer.setAttribute("class", C_BTN_CONTAINER);

    button = document.createElement("button");
    button.setAttribute("class", C_BTN);
    button.addEventListener("click", openStoryContent);

    buttonContainer.appendChild(button);

    body = document.querySelector("body");
    body.appendChild(buttonContainer);
}

/* triggered whenever a story is closed */
document.leave(`.${C_STORY_CONTAINER}`, function() {
    if (buttonExists()) {
        button.removeEventListener("click", openStoryContent);
        body.removeChild(buttonContainer);
    }
});

function openStoryContent(event) {
    /* checks if there's a story opened */
    let story = document.querySelector(`.${C_STORY_CONTAINER}`);
    if (story == null) {
        return;
    }

    let container = document.querySelector(`.${C_STORY_MEDIA_CONTAINER}`);
    let video = container.querySelector("video");
    let image = container.querySelector("img");
    if (video != null) {
        let videoElement = video.querySelector("source");
        let videoSource = videoElement != null ? videoElement.getAttribute("src") : null;
        if (videoSource == null || videoSource.length == 0) {
            alert("Failed to open video source");
            return;
        }
        window.open(videoSource, '_blank');
	} else if (image != null) {
        let imageSource = image.getAttribute("src");
        if (imageSource == null || imageSource.length == 0) {
            alert("Failed to open image source");
            return;
        }
		window.open(imageSource, '_blank');
	} else {
        alert("Failed to open media source");
    }
}

function buttonExists() {
    return (document.querySelector(`.${C_BTN_CONTAINER}`) != null);
}

/* creates the button when a story is opened via direct URL */
if (window.location.href.indexOf("stories/") > -1) {
    createButton();
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址