Google Knowledge Graph ID

View the ID of knowledge panels on Google search

Από την 31/12/2022. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Google Knowledge Graph ID
// @namespace    https://www.brandonfowler.me
// @version      1.0.0
// @description  View the ID of knowledge panels on Google search
// @author       Brandon Fowler
// @match        https://www.google.com/search*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

window.addEventListener('load', async () => {
	let kpActionEl = document.querySelector('[class*="kp-"] > :first-child');

	if (!kpActionEl) return;

	let controller = await kpActionEl.__jscontroller,
		id = controller.data.toArray()[1];

	if (!id) return;

	let el = document.createElement('div'),
		text = document.createElement('span'),
		copy = document.createElement('span'),
		link = document.createElement('a');

	text.innerText = 'Knowledge Graph ID: ' + id;
	text.style.marginRight = '8px';
	text.style.verticalAlign = 'middle';

	copy.title = 'Copy ID';
	copy.style.cursor = 'pointer';
	text.style.verticalAlign = 'middle';
	copy.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" style="width:16px;vertical-align:middle;" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2" /><rect x="9" y="3" width="6" height="4" rx="2" /></svg>';

	copy.addEventListener('click', async () => {
		await navigator.clipboard.writeText(id);

		copy.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" style="width:16px;vertical-align:middle;" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2" /><rect x="9" y="3" width="6" height="4" rx="2" /><path d="M9 14l2 2l4 -4" /></svg>';
	});

	link.title = 'Link';
    link.href = 'https://www.google.com/search?kgmid=' + id;
    link.style.color = 'inherit';
    text.style.verticalAlign = 'middle';
    link.innerText = 'link';
    link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" style="width:16px;vertical-align:middle;" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5" /><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5" /></svg>';

    el.style.marginBottom = '6px';
    el.append(text, copy, link);

    kpActionEl.parentNode.before(el);
});