utsavmadaan823 / Copy all elements text or attribute with CSS Selector

// ==UserScript==
// @name         Copy all elements text or attribute with CSS Selector
// @version      1.0
// @description  Will scrap & copy all elements text or attribute with CSS Selector 
// @author       utsavmadaan823
// @include      *
// @grant        none
// @license      MIT
// @run-at context-menu

// @downloadURL  https://openuserjs.org/install/utsavmadaan823/Copy_all_elements_text_or_attribute_with_CSS_Selector.user.js
// @updateURL    https://openuserjs.org/install/utsavmadaan823/Copy_all_elements_text_or_attribute_with_CSS_Selector.user.js

// ==/UserScript==

(function() {
    'use strict';

    var cssSelector = prompt("INPUT - Provide CSS Selector");
    var attribute = prompt("INPUT - Provide attribute or leave blank for text");
    var copyToClipboard = function (text) {
	  prompt("OUTPUT !!! Copy to clipboard: Ctrl+C & than press Enter", text);
	}
	
	var elements = document.querySelectorAll(cssSelector);
	if(elements.length>0){
		var outputArray=[];
		for (var i = 0; i < elements.length; i++) {
			if(attribute){
				outputArray.push(elements[i].getAttribute(attribute));
			}else{
				outputArray.push(elements[i].textContent);
			}
		}
		if(outputArray.length>0){
			copyToClipboard(outputArray.join("\n"));
		}else{
			alert("ERROR !!! Cannot obtain required value from elements.");
		}	
	}else{
		alert("ERROR !!! No elements found with provided selector");
	}
	
})();