Skip to content

Instantly share code, notes, and snippets.

@takuya
Last active August 11, 2017 08:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuya/63602863b932f3ceb50f to your computer and use it in GitHub Desktop.
Save takuya/63602863b932f3ceb50f to your computer and use it in GitHub Desktop.
var parseQueryString = function(str){
if(!str && window ){str=window.location.search.substring(1);}
pairs = str.split("&").filter(function(e){ return e})
params = {}
if( pairs.length > 0 )
pairs.forEach( function(e){ v=e.split("=");params[v[0]]=decodeURIComponent(v[1]) } )
return params;
}
var load_jQuery = function(arg){
if( typeof jQuery==="undefined"){
document.body.appendChild((function(onload_func) {
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js";
sc = document.createElement("script");
sc.type = "text/javascript";
sc.src = src;
sc.onload = function() {
onload_func();
};
return sc;
})(arg));
}
}
var post_to_yamato = function(values){
form_html = '<form action="http://toi.kuronekoyamato.co.jp/cgi-bin/tneko" method="POST">\n'
form_html += '<input type="hidden" name="number00" value="1">\n'
form_html += values.map(function(val,idx){ return '<input type="hidden" name="number0'+ (idx+1) +'" value="'+ val+'">';}).join("\n")
form_html += '</form>'
jQuery(form_html).submit();
}
var onload_main_function=function(){
params = parseQueryString();
values = Object.keys(params).filter(function(e){ return e.match(/^v|^id/)}).map(function(k){ return params[k] })
if(values.length>0){
post_to_yamato(values)
}
}
document.addEventListener( 'DOMContentLoaded', function(){
load_jQuery(onload_main_function)
},false );
/*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment