Tech Tangents:Sandbox: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
<html> | <html> | ||
<script> | |||
function upload_file() | function get_media_format() | ||
{ | { | ||
let result = ""; | |||
const inputs = document.querySelectorAll("#sc-Media_Format input[type='checkbox']"); | |||
inputs.forEach((input) => { | |||
if (input.checked) result += input.value + ","; | |||
}); | |||
if (result.length > 0) | |||
{ | |||
result = result.substring(0, result.length - 1); | |||
} | |||
return result; | |||
} | |||
function get_platform() | |||
{ | |||
let result = ""; | |||
} | const inputs = document.querySelectorAll("#sc-Platform input[type='checkbox']"); | ||
inputs.forEach((input) => { | |||
window.addEventListener("load", () => { | if (input.checked) result += input.value + ","; | ||
}); | |||
if (result.length > 0) | |||
{ | |||
result = result.substring(0, result.length - 1); | |||
} | |||
return result; | |||
} | |||
function get_paramter(parameter) | |||
{ | |||
if ( parameter == "Media Format") | |||
{ | |||
return get_media_format(); | |||
} | |||
if ( parameter == "Platform") | |||
{ | |||
return get_platform(); | |||
} | |||
parameter = parameter.replace(" ", "_") | |||
let element = document.getElementById("sc-"+parameter); | |||
if ( parameter == "Photo") | |||
{ | |||
file = document.getElementById("sc-file"); | |||
ext_pos = file.value.lastIndexOf('.'); | |||
ext = file.value.substring(ext_pos,file.value.length); | |||
return element.value !== "" ? element.value + ext : false ; | |||
} | |||
return element.value !== "" ? element.value : false ; | |||
} | |||
//function make_page(data) | |||
function make_page() | |||
{ | |||
let wikitext="{{InfoboxMedia"; | |||
parameters = [ | |||
"Title", | |||
"Photo", | |||
"Release Year", | |||
"Notes", | |||
"Notes Condition", | |||
"UPC", | |||
"Location", | |||
"Box Condition", | |||
"Media Format", | |||
"Platform", | |||
"Media Type" | |||
]; | |||
parameters.forEach(parameter => { | |||
value = get_paramter(parameter) | |||
if (value) | |||
{ | |||
wikitext+="|"+parameter+"="+value; | |||
} | |||
}); | |||
wikitext+="}}"; | |||
console.log( wikitext ); | |||
let params = { | |||
action: 'edit', | |||
title: get_paramter("Title"), | |||
text: wikitext, | |||
format: 'json' | |||
}; | |||
api = new mw.Api(); | |||
api.postWithToken( 'csrf', params ).done( function ( data ) { | |||
console.log( data ); | |||
} ); | |||
} | |||
function upload_file() | |||
{ | |||
let fileInput = document.getElementById("tt-input"); | |||
let license = "=={{int:license-header}}==\n{{Non-free game cover}}", | |||
api = new mw.Api(); | |||
file = document.getElementById("sc-file"); | |||
ext_pos = file.value.lastIndexOf('.'); | |||
ext = file.value.substring(ext_pos,file.value.length); | |||
name_input = get_paramter("Photo"); | |||
if (name_input == false) | |||
{ | |||
file_name = fileInput.files[0].name; | |||
}else{ | |||
file_name = name_input+ext; | |||
} | |||
let param = { | |||
filename: file_name, | |||
format: "json", | |||
ignorewarnings: 1, | |||
text: license | |||
}; | |||
api.upload(fileInput.files[0], param) | |||
.done(make_page) | |||
.fail(function (data) { | |||
console.log(data); | |||
}); | |||
} | |||
window.addEventListener("load", () => { | |||
let button = document.getElementById("tt-button"); | |||
//button.addEventListener("click", () => {make_page()}); | |||
button.addEventListener("click", () => {upload_file()}); | |||
}); | }); | ||
</script> | </script> | ||
<form> | |||
<fieldset id="photo-info"> | |||
<legend>Photo</legend> | |||
<div> | |||
<input type="file" id="sc-file"/> | |||
</div> | |||
<div> | |||
<label for="sc-Photo">Photo Name : </label> | |||
<input type="text" id="sc-Photo"/> | |||
</div> | |||
</fieldset> | |||
<fieldset id="software-info"> | |||
<legend>Software Info</legend> | |||
<div> | |||
<label for="sc-Title">Title : </label> | |||
<input type="text" id="sc-Title"/> | |||
</div> | |||
<div> | |||
<label for="sc-Release_Year">Release Year : </label> | |||
<input type="number" id="sc-Release_Year" value="1999"/> | |||
</div> | |||
<div> | |||
<label for="sc-Notes">Notes : </label> | |||
<input type="text" id="sc-Notes"/> | |||
</div> | |||
<div> | |||
<label for="sc-Notes_Condition">Notes Condition : </label> | |||
<input type="text" id="sc-Notes_Condition"/> | |||
</div> | |||
<div> | |||
<label for="sc-UPC">UPC : </label> | |||
<input type="number" id="sc-UPC"/> | |||
</div> | |||
<div> | |||
<label for="sc-Location">Location : </label> | |||
<input type="text" id="sc-Location"/> | |||
</div> | |||
<div> | |||
<label for="sc-Media_Type">Media Type : </label> | |||
<input type="text" list="sc-Media_Type-data" id="sc-Media_Type" value="Software"/> | |||
<datalist id="sc-Media_Type-data"> | |||
<option value="Software"></option> | |||
</datalist> | |||
</div> | |||
<div> | |||
<label for="sc-Box_Condition">Box Condition:</label> | |||
<select id="sc-Box_Condition"> | |||
<option value="">Select Box Condition...</option> | |||
<option value="5 - Like New">5 - Like New</option> | |||
<option value="4 - Nice, but not perfect">4 - Nice, but not perfect</option> | |||
<option value="3 - Creases, mild crushing, light fading">3 - Creases, mild crushing, light fading</option> | |||
<option value="2 - Corner tears, bad crushing, bad fading">2 - Corner tears, bad crushing, bad fading</option> | |||
<option value="1 - Water damage, missing parts, bleached">1 - Water damage, missing parts, bleached</option> | |||
</select> | |||
</div> | |||
<div> | |||
<fieldset id="sc-Media_Format"> | |||
<legend>Media Format:</legend> | |||
<div> | |||
<input type="checkbox" id="fmt-CDROM" | |||
value="CD-ROM" | |||
/> | |||
<label for="fmt-CDROM">CD-ROM</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="fmt-DVD" | |||
value="DVD" | |||
/> | |||
<label for="fmt-DVD">DVD</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="fmt-MFDD" | |||
value="3.5in 720KB DD Floppy Disk" | |||
/> | |||
<label for="fmt-MFDD">3.5in 720KB DD Floppy Disk</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="fmt-MFHD" | |||
value="3.5in 1.44MB HD Floppy Disk" | |||
/> | |||
<label for="fmt-MFHD">3.5in 1.44MB HD Floppy Disk</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="fmt-MDDD" | |||
value="5.25in 360KB DD Floppy Disk" | |||
/> | |||
<label for="fmt-MDDD">5.25in 360KB DD Floppy Disk</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="fmt-MDHD" | |||
value="5.25in 1.2MB HD Floppy Disk" | |||
/> | |||
<label for="fmt-MDHD">5.25in 1.2MB HD Floppy Disk</label> | |||
</div> | |||
<div> | |||
<label for="fmt-custom">New Format : </label> | |||
<input type="text" id="fmt-custom"/> | |||
</div> | |||
</fieldset> | |||
</div> | |||
<div> | |||
<fieldset id="sc-Platform"> | |||
<legend>Platform:</legend> | |||
<div> | |||
<input type="checkbox" id="platform-IBMPC" | |||
value="IBM PC" | |||
/> | |||
<label for="platform-IBMPC">IBM PC</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-MAC68K" | |||
value="Macintosh (M68000)" | |||
/> | |||
<label for="platform-MAC68K">Macintosh (M68000)</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-C64" | |||
value="Commodore 64" | |||
/> | |||
<label for="platform-C64">Commodore 64</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-MACPPC" | |||
value="Mac (PowerPC)" | |||
/> | |||
<label for="platform-MACPPC">Mac (PowerPC)</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-Linux" | |||
value="Linux" | |||
/> | |||
<label for="platform-Linux">Linux</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-AtariST" | |||
value="Atari ST" | |||
/> | |||
<label for="platform-AtariST">Atari ST</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-TRS80M1" | |||
value="TRS-80 Model I" | |||
/> | |||
<label for="platform-TRS80M1">TRS-80 Model I</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-TRS80M4" | |||
value="TRS-80 Model 4" | |||
/> | |||
<label for="platform-TRS80M4">TRS-80 Model 4</label> | |||
</div> | |||
<div> | |||
<input type="checkbox" id="platform-TRS80M2" | |||
value="TRS-80 Model II" | |||
/> | |||
<label for="platform-TRS80M2">TRS-80 Model II</label> | |||
</div> | |||
<div> | |||
<label for="platform-custom">New Platform : </label> | |||
<input type="text" id="platform-custom"/> | |||
</div> | |||
</fieldset> | |||
</div> | |||
</fieldset> | |||
<input type="button" id="tt-button" value="Upload" /> | |||
</form> | |||
</html> | </html> |
Revision as of 21:10, 7 September 2024