aboutsummaryrefslogtreecommitdiff
path: root/phttps___drive.google.com_file_d___.json
blob: fdb91073fb1c351b9f2494c52a7f72dc831d0038 (plain)
1
[{"sgoogle drive download file":{"url":"","hash":"","text":"/**\n * Copyright 2021 Wojtek Kosior\n *\n * This program is free software; you can redistribute it\n * and/or modify it under the terms of either:\n * - the GNU General Public License as published by the Free\n *   Software Foundation; either version 3 of the License, or (at\n *   your option) any later version, or\n * - the \"A\" license: <https://koszko.org/alicense.txt>; explained\n *   at: <https://koszko.org/en/articles/my-new-license.html>\n *\n * As additional permission under GNU GPL version 3 section 7, you\n * may distribute forms of that code without the copy of the GNU\n * GPL normally required by section 4, provided you include this\n * license notice and, in case of non-source distribution, a URL\n * through which recipients can access the Corresponding Source.\n * If you modify file(s) with this exception, you may extend this\n * exception to your version of the file(s), but you are not\n * obligated to do so. If you do not wish to do so, delete this\n * exception statement from your version. If you delete this\n * exception statement from all source files in the program, then\n * also delete it here.\n *\n * As a special exception to the GPL, any HTML file which merely\n * makes function calls to this code, and for that purpose\n * includes it by reference shall be deemed a separate work for\n * copyright law purposes. If you modify this code, you may extend\n * this exception to your version of the code, but you are not\n * obligated to do so. If you do not wish to do so, delete this\n * exception statement from your version.\n */\n\nconst og = {};\n\nfor (const node of document.head.childNodes) {\n    if (node.tagName === \"STYLE\") {\n\tdocument.head.removeChild(node);\n\tcontinue;\n    }\n\n    if (node.tagName !== \"META\")\n\tcontinue;\n\n    const match = /^og:(.+)/.exec(node.getAttribute(\"property\"));\n    if (!match)\n\tcontinue;\n\n    og[match[1]] = node.getAttribute(\"content\");\n}\n\nlet download_link = null;\n\nconst match = new RegExp(\"/file/d/([^/]+)\").exec(document.URL);\nif (match)\n    download_link = `https://drive.google.com/uc?export=download&id=${match[1]}`;\n\nconst body = document.createElement(\"body\");\nconst name_div = document.createElement(\"div\");\nconst download_div = document.createElement(\"div\");\nconst download_button = document.createElement(\"a\");\nconst type_div = document.createElement(\"div\");\nconst type_span = document.createElement(\"span\");\nconst show_image_div = document.createElement(\"div\");\nconst show_image_button = document.createElement(\"button\");\nconst image = document.createElement(\"img\");\n\n\nlet button_text = \"download\";\n\nif (!og.title)\n    button_text += \" file\";\nelse\n    name_div.textContent = og.title;\n\nname_div.setAttribute(\"style\", \"font-weight: bold; display:inline-block;\");\n\n\nif (download_link)\n    download_button.setAttribute(\"href\", download_link);\nelse\n    button_text += \" (unavailable)\";\n\ndownload_button.textContent = button_text;\ndownload_button.setAttribute(\"style\", \"border-radius: 5px; padding: 10px; color: black; background-color: lightgreen; text-decoration: none; box-shadow: -4px 8px 8px #888;\");\n\n\ndownload_div.appendChild(download_button);\ndownload_div.setAttribute(\"style\", \"padding: 10px; display: inline-block; margin: 0 0 10px;\");\n\n\ntype_span.textContent = \"type: \";\ntype_span.setAttribute(\"style\", \"font-weight: bold; display:inline-block; white-space: pre;\");\n\ntype_div.setAttribute(\"style\", \"margin: 0 0 10px;\");\ntype_div.appendChild(type_span);\nif (og.type)\n    type_div.append(og.type);\n\n\nfunction show_image()\n{\n    const image = document.createElement(\"img\");\n    image.setAttribute(\"src\", og.image);\n    image.setAttribute(\"width\", og[\"image:width\"]);\n    image.setAttribute(\"height\", og[\"image:height\"]);\n    image.setAttribute(\"style\", \"border: 1px solid #eee;\");\n\n    document.body.replaceChild(image, show_image_div);\n}\n\nshow_image_button.setAttribute(\"style\", \"border-radius: 5px; padding: 10px; color: black; background-color: lightgreen; box-shadow: -4px 8px 8px #888; font-family: inherit; font-size: inherit; border: none;\");\nshow_image_button.textContent = \"show image\";\nshow_image_button.addEventListener(\"click\", show_image);\nshow_image_div.appendChild(show_image_button);\n\n\nbody.setAttribute(\"style\", \"margin: 20px;\");\nif (og.title)\n    body.appendChild(name_div);\nbody.appendChild(download_div);\nif (og.type)\n    body.appendChild(type_div);\nif (og.image && og[\"image:width\"] && og[\"image:height\"])\n    body.appendChild(show_image_div);\n\ndocument.documentElement.replaceChild(body, document.body);\n"}},{"phttps://drive.google.com/file/d/**":{"allow":false,"components":["s","google drive download file"]}}]