Last active
December 21, 2022 07:55
-
-
Save og24715/69abdf7c0a9c758197b1d76a2e2529d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Return Product Page After Login | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author og24715 | |
// @match https://www.melonbooks.co.jp/mypage/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=melonbooks.co.jp | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getLoginForm() { | |
return document.forms.namedItem('login_mypage') | |
} | |
function createReturnUrlInput(url) { | |
const input = document.createElement('input'); | |
input.setAttribute('type', 'hidden'); | |
input.setAttribute('name', 'return_url'); | |
input.value = url; | |
return input | |
} | |
const loginForm = getLoginForm() | |
// ログイン後と前で同じページなのでログインフォームの有無を確認する | |
if (!loginForm) { | |
return | |
} | |
const returnUrlInput = document.querySelector('input[name="return_url"]'); | |
if (returnUrlInput) { | |
return | |
} | |
// const urlSearchParams = new URLSearchParams({ ru: document.referrer }) | |
// console.log(document, urlSearchParams.get('ru'), urlSearchParams.toString()) | |
// location.search = urlSearchParams.toString(); | |
loginForm.insertAdjacentElement('afterBegin', createReturnUrlInput(document.referrer)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment