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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
})();