|
|
(3 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| <html>
| | {{#ask: [[Doom II]]|?From Year}} |
| <style>
| |
| input[type=text],
| |
| input[type=number],
| |
| select
| |
| {
| |
| display: block;
| |
| width: 100%;
| |
| }
| |
| form
| |
| { | |
| max-width: 30em;
| |
| }
| |
| </style>
| |
| <script>
| |
| | |
| function get_media_format()
| |
| { | |
| let result = "";
| |
| | |
| // Standad format checkboxes
| |
| const inputs = document.querySelectorAll("#sc-Media_Format input[type='checkbox']");
| |
| | |
| inputs.forEach((input) => {
| |
| if (input.checked) result += input.value + ",";
| |
| });
| |
| | |
| // Custom Value for usuual formats
| |
| let element = document.getElementById("fmt-custom");
| |
| if ( element.value !== "" )
| |
| {
| |
| result += element.value + ",";
| |
| }
| |
| | |
| // Trim off last comma
| |
| if (result.length > 0)
| |
| {
| |
| result = result.substring(0, result.length - 1);
| |
| }
| |
| return result;
| |
| }
| |
| | |
| function get_platform()
| |
| {
| |
| let result = "";
| |
| | |
| // Standad platform checkboxes
| |
| const inputs = document.querySelectorAll("#sc-Platform input[type='checkbox']");
| |
| | |
| inputs.forEach((input) => {
| |
| if (input.checked) result += input.value + ",";
| |
| });
| |
| | |
| // Custom Value for usuual platforms
| |
| let element = document.getElementById("platform-custom");
| |
| if ( element.value !== "" )
| |
| {
| |
| result += element.value + ",";
| |
| }
| |
| | |
| // Trim off last comma
| |
| if (result.length > 0)
| |
| {
| |
| result = result.substring(0, result.length - 1);
| |
| }
| |
| return result;
| |
| }
| |
| | |
| function get_paramter(parameter)
| |
| {
| |
| // Multiple input parameters
| |
| if ( parameter == "Media Format")
| |
| {
| |
| return get_media_format();
| |
| }
| |
| if ( parameter == "Platform")
| |
| {
| |
| return get_platform();
| |
| }
| |
| | |
| // Get IDs using parameter as name
| |
| parameter = parameter.replace(" ", "_")
| |
| let element = document.getElementById("sc-"+parameter);
| |
| | |
| // Add extension to filename of Photo
| |
| 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 value if it was set
| |
| return element.value !== "" ? element.value : false ;
| |
| }
| |
| | |
| //function make_page(data)
| |
| function make_page()
| |
| {
| |
| // Init page contents with template name
| |
| let wikitext="{{InfoboxMedia";
| |
| | |
| // Template parameters
| |
| parameters = [
| |
| "Title",
| |
| "Photo",
| |
| "Release Year",
| |
| "Notes",
| |
| "Notes Condition",
| |
| "UPC",
| |
| "Location",
| |
| "Box Condition",
| |
| "Media Format",
| |
| "Platform",
| |
| "Media Type"
| |
| ];
| |
| | |
| // Iterate all parameters to get input values as template text
| |
| parameters.forEach(parameter => {
| |
| value = get_paramter(parameter)
| |
| if (value)
| |
| {
| |
| wikitext+="|"+parameter+"="+value;
| |
| }
| |
| });
| |
| | |
| // End template
| |
| wikitext+="}}";
| |
| | |
| // Log final wikitext for page
| |
| console.log( wikitext );
| |
| | |
| // Setup API data
| |
| let params = {
| |
| action: 'edit',
| |
| title: get_paramter("Title"), // New page title
| |
| text: wikitext, // Page Contents
| |
| format: 'json'
| |
| };
| |
| | |
| // Get Mediawiki API
| |
| api = new mw.Api();
| |
| | |
| // Submit API request to create new page
| |
| api.postWithToken( 'csrf', params ).done( function ( data ) {
| |
| console.log( data );
| |
| // Redirect to new page after creating it
| |
| window.location.replace("https://wiki.techtangents.net/wiki/"+get_paramter("Title").replace(" ", "_"));
| |
| } );
| |
| }
| |
| | |
| function upload_file()
| |
| {
| |
| // Get file input
| |
| let fileInput = document.getElementById("sc-file");
| |
| // Licesne for all software boxes are set to Non-free game cover
| |
| let license = "=={{int:license-header}}==\n{{Non-free game cover}}",
| |
| | |
| // Get Mediawiki API
| |
| api = new mw.Api();
| |
| | |
| // Get name for file page
| |
| name_input = get_paramter("Photo");
| |
| | |
| // If a custom filename was not set use actual filename
| |
| if (name_input == false)
| |
| {
| |
| file_name = fileInput.files[0].name;
| |
| }else{
| |
| file_name = name_input;
| |
| }
| |
| | |
| // Setup API data
| |
| let param = {
| |
| filename: file_name,
| |
| format: "json",
| |
| ignorewarnings: 1,
| |
| text: license
| |
| };
| |
| | |
| // Submit API request to upload file
| |
| api.upload(fileInput.files[0], param)
| |
| .done(make_page) // Make page after upload finished
| |
| .fail(function (data) {
| |
| console.log(data);
| |
| });
| |
| }
| |
| | |
| | |
| window.addEventListener("load", () => {
| |
| // Hook button click to JS code
| |
| let button = document.getElementById("tt-button");
| |
| button.addEventListener("click", () => {upload_file()});
| |
| });
| |
| </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="Create Page" />
| |
| </form>
| |
| | |
| | |
| </html>
| |