360photocam.com - Download panorama button

Adds a button to 360photocam.com's panorama viewer to download the panorama image

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        360photocam.com - Download panorama button
// @description Adds a button to 360photocam.com's panorama viewer to download the panorama image
// @namespace   me.netux.site/user-scripts/360-photocam/download-panorama
// @match       https://360photocam.com/online-viewer*
// @grant       none
// @version     1.0.0
// @author      Netux
// @license     MIT
// @run-at      document-end
// @require     https://cdn.jsdelivr.net/npm/@violentmonkey/[email protected]
// ==/UserScript==

(() => {
  let panoUrl;

  for (const scriptEl of document.querySelectorAll('script')) {
    const match = scriptEl.textContent.match(/const imageData\s*=\s*(["'])(?<panoUrl>data:image\\\/jpeg;base64,.+)\1/);
    if (match) {
      panoUrl = eval(`"${match.groups.panoUrl}"`);
      break;
    }
  }

  const buttonsRowEl = document.querySelector('.second-section .conatiner.frm__btnn .row');
  {
    const eightColButtonContainerEl = buttonsRowEl.querySelector('.col-md-8');
    eightColButtonContainerEl.classList.remove('col-md-8');
    eightColButtonContainerEl.classList.add('col-md-4');
  }

  const downloadButtonEl = VM.hm('button', { class: 'make__button' }, 'Download panorama');
  downloadButtonEl.addEventListener('click', async () => {
    const blob = await fetch(panoUrl).then((res) => res.blob());
    const blobUrl = URL.createObjectURL(blob);

    window.open(blobUrl, /* target: */ '_blank');
  });

  buttonsRowEl.append(
    VM.hm('div', { class: 'col-md-4' }, [
      VM.hm('div', { class: 'make_btn' }, [
        downloadButtonEl
      ])
    ])
  );
})();