WordPress.org Plugins

Adds Copy URL and Copy Name buttons

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         WordPress.org Plugins
// @namespace    https://wpdevdesign.com/
// @version      0.1
// @description  Adds Copy URL and Copy Name buttons
// @author       Sridhar Katakam
// @match        https://wordpress.org/plugins/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=wordpress.org
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {

	'use strict';

	function copyToClipboard(event) {
		const buttonText = event.target.textContent;
		let helper = document.createElement('input');

		document.body.appendChild(helper);
		helper.value = this.value;
		helper.select();
		document.execCommand('copy');
		this.textContent = "Copied ✓";
		setTimeout(() => {
			this.textContent = buttonText;
		}, 1000)
		helper.remove();

		event.preventDefault();
		event.stopPropagation();
	}

	const entryHeaders = document.getElementsByClassName('entry-header');

	document.querySelectorAll('.entry-header').forEach(el => {
		el.querySelector('.entry-title').style.cssText = "margin-bottom: 0;";
		let href = el.querySelector('.entry-title a').href;
		let name = el.querySelector('.entry-title a').textContent;

		let buttonStyles = "cursor: pointer; border-radius: 4px; padding: 5px 10px; border: 1px solid #fff; font-size: 11px; background-color: #3e58e1; color: #fff; min-width: 82px;";
		let buttonHoverStyles = "cursor: pointer; border-radius: 4px; padding: 5px 10px; border: 1px solid #fff; font-size: 11px; background-color: #213fd4; color: #fff; min-width: 82px;";

		let copyUrlButton = document.createElement("button");
		copyUrlButton.textContent = "Copy Link";
		copyUrlButton.value = href;
		copyUrlButton.style.cssText = buttonStyles;
		copyUrlButton.addEventListener('mouseover',function(){
			this.style.cssText = buttonHoverStyles;
		})
		copyUrlButton.addEventListener('mouseleave',function(){
			this.style.cssText = buttonStyles;
		})
		copyUrlButton.addEventListener("click", copyToClipboard);

		let copyNameButton = document.createElement("button");
		copyNameButton.textContent = "Copy Name";
		copyNameButton.value = name;
		copyNameButton.style.cssText = buttonStyles;
		copyNameButton.addEventListener('mouseover',function(){
			this.style.cssText = buttonHoverStyles;
		})
		copyNameButton.addEventListener('mouseleave',function(){
			this.style.cssText = buttonStyles;
		})
		copyNameButton.addEventListener("click", copyToClipboard);

		let buttonsDiv = document.createElement("div");
		buttonsDiv.className = 'entry-buttons';
        buttonsDiv.style.cssText = "display: flex; gap: 6px; align-items: center; margin-top: 8px; margin-bottom: 8px;";

        el.append(buttonsDiv);

		buttonsDiv.append(copyUrlButton);
		buttonsDiv.append(copyNameButton);
	});

})();