🏠 返回首頁 

Greasy Fork is available in English.

Instagram Embed Link Copier for Discord

Adds two buttons to copy Instagram post links with modified URLs for proper embedding on Discord. One adds "dd" before "instagram" and the other adds "ez" after "instagram".


安装此脚本?
// ==UserScript==
// @name         Instagram Embed Link Copier for Discord
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Adds two buttons to copy Instagram post links with modified URLs for proper embedding on Discord. One adds "dd" before "instagram" and the other adds "ez" after "instagram".
// @author       FunkyJustin
// @match        https://www.instagram.com/*
// @license      MIT
// @grant        none
// ==/UserScript==
(function() {
'use strict';
// Function to create custom toast notifications
function createToast(message) {
const toast = document.createElement('div');
toast.textContent = message;
toast.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background-color: rgba(0, 0, 0, 0.8);
color: white;
padding: 10px 20px;
border-radius: 5px;
font-size: 14px;
z-index: 10000;
opacity: 1;
transition: opacity 0.5s ease;
`;
document.body.appendChild(toast);
// Automatically remove the toast after 1 second
setTimeout(() => {
toast.style.opacity = '0';
setTimeout(() => {
toast.remove();
}, 500);
}, 1000);
}
// Function to create the copy buttons
function createCopyButtons() {
const buttonSections = document.querySelectorAll('section.x6s0dn4.xrvj5dj.x1o61qjw.x12nagc.x1gslohp, section.x6s0dn4.xrvj5dj.x1o61qjw');
buttonSections.forEach((section) => {
// Check if the buttons already exist to avoid duplicates
if (!section.querySelector('.copy-link-btn') && !section.querySelector('.copy-ez-link-btn')) {
// Create the "ddinstagram" button
const ddButton = document.createElement('button');
ddButton.innerText = 'Copy dd Link';
ddButton.className = 'copy-link-btn';
ddButton.style.cssText = 'padding: 3px 8px; background-color: #3897f0; color: white; border: none; border-radius: 3px; cursor: pointer; margin-left: 6px; font-size: 12px;';
// Create the "instagramez" button
const ezButton = document.createElement('button');
ezButton.innerText = 'Copy ez Link';
ezButton.className = 'copy-ez-link-btn';
ezButton.style.cssText = 'padding: 3px 8px; background-color: #f02a2a; color: white; border: none; border-radius: 3px; cursor: pointer; margin-left: 6px; font-size: 12px;';
// Add click event listener to copy the "ddinstagram" URL
ddButton.addEventListener('click', function() {
let originalLink;
// Check if the URL contains "/p/" for a post
if (window.location.href.includes('/p/')) {
originalLink = window.location.href; // Use the post URL
} else {
const postLinkElement = section.closest('article').querySelector('a[href*="/p/"]');
originalLink = postLinkElement ? postLinkElement.href : null; // Try to find the post link
}
if (originalLink) {
let modifiedLink = originalLink.replace('www.instagram.com', 'www.ddinstagram.com');
copyToClipboard(modifiedLink);
createToast('Modified "dd" link copied!');
} else {
createToast('Failed to find post link.');
}
});
// Add click event listener to copy the "instagramez" URL
ezButton.addEventListener('click', function() {
let originalLink;
// Check if the URL contains "/p/" for a post
if (window.location.href.includes('/p/')) {
originalLink = window.location.href; // Use the post URL
} else {
const postLinkElement = section.closest('article').querySelector('a[href*="/p/"]');
originalLink = postLinkElement ? postLinkElement.href : null; // Try to find the post link
}
if (originalLink) {
let modifiedLink = originalLink.replace('instagram.com', 'instagramez.com');
copyToClipboard(modifiedLink);
createToast('Modified "ez" link copied!');
} else {
createToast('Failed to find post link.');
}
});
// Add the buttons side by side
const buttonContainer = document.createElement('div');
buttonContainer.style.cssText = 'display: inline-flex; align-items: center;';
buttonContainer.appendChild(ddButton);
buttonContainer.appendChild(ezButton);
// Add the button container to the section
section.appendChild(buttonContainer);
}
});
}
// Function to copy text to the clipboard
function copyToClipboard(text) {
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
}
// Run the script after the DOM has fully loaded
window.addEventListener('load', () => {
// Observe changes to the page content for dynamically loaded posts
const observer = new MutationObserver(() => {
createCopyButtons();
});
observer.observe(document.body, { childList: true, subtree: true });
});
})();