Automatically select and copy a translation from IATE (Tampermonkey script)

spiros · 1 · 4692

spiros

  • Administrator
  • Hero Member
  • *****
    • Posts: 855844
    • Gender:Male
  • point d’amour
You use IATE often and you find it hard to select/copy a translation? Translatum has a feature whereby from search results you can simply click an icon to copy the desired text (Click to copy in search results). Something similar can be applied to IATE by using the browser extension Tampermonkey.

Once you install and activate the extension, create a new script and add the following content. Once this is done, and the script is enabled, you can simply click on a term translation in IATE and it will be automatically selected and copied. Now you can paste it anywhere you want by pressing CTRL+V.

Code: [Select]
// ==UserScript==
// @name         Iate select and copy
// @version      0.1
// @author       translatum.gr
// @description  Select and copy IATE translation by clicking on it - more here: translatum.gr/forum/index.php?topic=1016221.0
// @match        https://iate.europa.eu/*
// @require      https://gist.githubusercontent.com/BrockA/2625891/raw/waitForKeyElements.js
// @grant        GM_setClipboard
// @grant        GM_addStyle
// ==/UserScript==
/* globals waitForKeyElements */

(function() {
    'use strict';

    GM_addStyle('app-iate-search-term-refine { user-select: all !important; }');

    waitForKeyElements('app-iate-search-term-refine', addListener, false);

    function addListener() {
        const elements = document.querySelectorAll('app-iate-search-term-refine');

        elements.forEach(element => {
            element.addEventListener('click', () => {
                const text = element.textContent.trim();

                GM_setClipboard(text);
            });
        });
    }
})();

« Last Edit: 24 Dec, 2022, 10:18:12 by spiros »


 

Search Tools