Elsevier Extract Section Titles

Extracts section and titles from a webpage (e.g., Elsevier papers), and allows you to copy them to the clipboard by clicking a button.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Elsevier Extract Section Titles
// @namespace    yuhuangmeng
// @version      1.0.1
// @description  Extracts section and titles from a webpage (e.g., Elsevier papers), and allows you to copy them to the clipboard by clicking a button.
// @author       yuhuangmeng
// @homepageURL  https://greasyfork.org/zh-CN/users/1065289-yuhuangmeng
// @match        https://www.sciencedirect.com/*
// @match        https://www-sciencedirect-com.tudelft.idm.oclc.org/*
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

/**
 * TODO:
 * 1.
 */

(function() {
    'use strict';

    // Function to extract section titles from the page
    function extractSectionTitles() {
        var sections = document.querySelectorAll('section');
        var titles = [];
        for (var i = 0; i < sections.length; i++) {
            var h2 = sections[i].querySelector('h2');
            if (h2) {
                titles.push(h2.textContent);
            }
            var h3 = sections[i].querySelector('h3');
            if (h3) {
                titles.push(' - ' + h3.textContent);
            }
            var h4 = sections[i].querySelector('h4');
            if (h4) {
                titles.push('    - ' + h4.textContent);
            }
        }
        return titles;
    }

    // Add a button to the page to extract and copy section titles
    var button = document.createElement('button');
    button.innerText = 'Extract Section Titles';
    button.style = `
        position: fixed;
        bottom: 40px;
        right: 10px;
        // width: 128px;
        background-color: hsla(200, 40%, 96%, .8);
        font-size: 16px;
        border-radius: 6px;
        z-index: 99999;`;
    button.addEventListener('click', function() {
        var titles = extractSectionTitles();
        GM_setClipboard(titles.join('\n'));
        alert('Section titles have been copied to the clipboard.');
    });
    document.body.appendChild(button);
})();