2022-06-25 03:26:17 +02:00
var zip = new JSZip ( ) ;
2022-06-26 15:04:39 +02:00
var archive _name = "" ;
var fout = document . getElementById ( 'added-files' ) ;
function isFileImage ( file ) {
return file && file [ 'type' ] . split ( '/' ) [ 0 ] === 'image' ;
}
2022-06-25 03:26:17 +02:00
2022-03-27 19:58:39 +02:00
function check _checkboxes ( name ) {
const checkboxes = document . querySelectorAll ( ` input[name=" ${ name } "]:checked ` ) ;
let values = [ ] ;
checkboxes . forEach ( ( checkbox ) => {
2022-06-08 06:09:50 +02:00
values . push ( "\"" + checkbox . value + "\"" ) ;
2022-03-27 19:58:39 +02:00
} ) ;
if ( values ) {
return values ;
} else {
return null ;
}
}
2022-06-24 13:51:48 +02:00
function clearThis ( target ) {
var id = document . getElementById ( target ) ;
id . value = "" ;
}
function Input ( str ) {
var arr = str . split ( ";" ) ;
let x = arr [ 1 ] ;
let target = arr [ 0 ] ;
var id = document . getElementById ( target ) ;
var value = id . value ;
function typeInInputfield ( newText , el = document . getElementById ( target ) ) {
const [ start , end ] = [ el . selectionStart , el . selectionEnd ] ;
el . setRangeText ( newText , start , end ) ;
}
var out = x ;
if ( value ) {
var out = "," + x ;
}
if ( out != null ) {
typeInInputfield ( out ) ;
var end = id . value . length ;
id . setSelectionRange ( end , end ) ;
2022-06-24 22:24:02 +02:00
id . focus ( { preventScroll : true } ) ;
2022-06-24 13:51:48 +02:00
}
}
2022-06-25 03:26:17 +02:00
function handleFile ( f ) {
var name = f . name ;
var data = f . raw ;
zip . file ( name , data ) ;
2022-06-08 06:09:50 +02:00
}
2022-06-25 03:26:17 +02:00
function Clear ( name ) {
var ele = document . getElementsByName ( name ) ;
for ( var i = 0 ; i < ele . length ; i ++ )
ele [ i ] . checked = false ;
}
2022-06-07 13:36:28 +02:00
2022-06-25 05:36:48 +02:00
function rm _file ( fname ) {
var rmid = document . getElementById ( fname ) ;
rmid . remove ( ) ; // Removes the div with the 'div-02' id
zip . remove ( fname ) ;
}
2022-06-26 15:04:39 +02:00
function insert _file ( fname ) {
var arr = fname . split ( ";" ) ;
let t = arr [ 2 ] ;
let x = arr [ 1 ] ;
let target = arr [ 0 ] ;
2022-06-26 15:40:56 +02:00
if ( ! ( x . startsWith ( "banner" ) ) ) {
var id = document . getElementById ( target ) ;
function typeInTextarea ( newText , el = id ) {
const [ start , end ] = [ el . selectionStart , el . selectionEnd ] ;
el . setRangeText ( newText , start , end ) ;
}
if ( t == "image" ) {
var n = prompt ( "Name" , "Wikipedia Logo" ) ;
var desc = prompt ( "Describe the Picture for the Blind" , "A Globe composed of letters and puzzle pieces" ) ;
2022-06-26 15:49:16 +02:00
if ( desc != null && n != null ) { var out = "\n![" + n + "](" + x + " \"" + desc + "\"" + ")\n" ; }
2022-06-26 15:40:56 +02:00
} else if ( t == "other" ) {
var n = prompt ( "Name" , "Textfile" ) ;
var desc = prompt ( "Describe the File for the Blind" , "A file with content related to the subject" ) ;
2022-06-26 15:49:16 +02:00
if ( desc != null && n != null ) { var out = "\n[" + n + "](" + x + " \"" + desc + "\"" + ")\n" ; }
2022-06-26 15:40:56 +02:00
}
if ( out != null ) {
typeInTextarea ( out ) ;
var end = id . value . length ;
id . setSelectionRange ( end , end ) ;
id . focus ( { preventScroll : true } ) ;
}
2022-06-26 15:04:39 +02:00
}
}
function addfiles ( str ) {
var arr = str . split ( ";" ) ;
let x = arr [ 1 ] ;
let target = arr [ 0 ] ;
var input = document . createElement ( 'input' ) ;
var type = "image" ;
input . type = 'file' ;
input . multiple = 'multiple' ;
input . id = 'inpic' ;
input . click ( ) ;
input . onchange = e => {
var files = e . target . files ;
for ( var i = 0 ; i < files . length ; i ++ ) {
var name = files [ i ] . name . trim ( ) ;
if ( isFileImage ( files [ i ] ) ) {
type = "image" ;
} else {
type = "other"
}
zip . file ( name , files [ i ] ) ;
fout . innerHTML += "<div id=\"" + name + "\" style=\"display: flex; flex-direction: row;\">" + "<button type=\"button\" onclick=\"insert_file('" + target + ";" + name + ";" + type + "')\" value=\"" + name + "\" id=\"" + name + "\" class=\"button\">Einfügen</button>" + "<button type=\"button\" onclick=\"rm_file('" + name + "')\" value=\"" + name + "\" id=\"" + name + "\" class=\"button\">Entfernen</button>" + name + "</div>" ;
}
}
}
2022-06-13 00:59:41 +02:00
function button ( str ) {
2022-06-13 04:08:02 +02:00
var arr = str . split ( ";" ) ;
2022-06-13 00:59:41 +02:00
let x = arr [ 1 ] ;
2022-06-13 04:08:02 +02:00
let target = arr [ 0 ] ;
var id = document . getElementById ( target ) ;
function typeInTextarea ( newText , el = document . getElementById ( target ) ) {
const [ start , end ] = [ el . selectionStart , el . selectionEnd ] ;
el . setRangeText ( newText , start , end ) ;
}
2022-06-07 13:36:28 +02:00
if ( x == "url" ) {
let url = prompt ( "Please enter URL" , "https://wikipedia.org" ) ;
2022-06-12 13:50:06 +02:00
if ( url != null ) {
2022-06-26 15:40:56 +02:00
var n = prompt ( "Name" , "Wikipedia" ) ;
var desc = prompt ( "Describe the Link for the Blind" , "The free Encyclopedia" ) ;
2022-06-26 15:49:16 +02:00
if ( desc != null && n != null ) { var out = "![" + n + "](" + url + " \"" + desc + "\"" + ") " ; }
2022-06-12 13:50:06 +02:00
}
2022-06-07 13:36:28 +02:00
}
2022-06-26 15:04:39 +02:00
if ( x == "picurl" ) {
let url = prompt ( "Please enter Link to an image" , "https://de.wikipedia.org/static/images/project-logos/dewiki.png" ) ;
if ( url != null ) {
2022-06-26 15:40:56 +02:00
var n = prompt ( "Name" , "Wikipedia Logo" ) ;
2022-06-26 15:49:16 +02:00
var desc = prompt ( "Describe the Picture for the Blind" , "A Globe composed of letters and puzzle pieces" ) ; if ( desc != null && n != null ) { var out = "\n![" + n + "](" + url + " \"" + desc + "\"" + ")\n" ; }
2022-06-26 15:04:39 +02:00
}
}
2022-06-07 13:36:28 +02:00
if ( x == "headline" ) {
let headline = prompt ( "Headline" , "Act One" ) ;
2022-06-12 13:50:06 +02:00
if ( headline != null ) { var out = "## " + headline + "\n\n" ; }
2022-06-07 13:36:28 +02:00
}
if ( x == "bold" ) {
let bold = prompt ( "Bold" , "" ) ;
2022-06-12 13:50:06 +02:00
if ( bold != null ) { var out = "\*\*" + bold + "\*\* " ; }
2022-06-07 13:36:28 +02:00
}
2022-06-23 10:32:21 +02:00
if ( x == "strike" ) {
let strike = prompt ( "Strike" , "" ) ;
if ( strike != null ) { var out = "\~\~" + strike + "\~\~ " ; }
}
2022-06-07 13:36:28 +02:00
if ( x == "paragraph" ) {
var out = "\n\n" ;
}
if ( x == "newline" ) {
var out = " \n" ;
}
if ( x == "more" ) {
2022-06-13 04:08:02 +02:00
var out = "\n\n<!--more-->\n\n" ;
2022-06-07 13:36:28 +02:00
}
2022-06-25 05:36:48 +02:00
if ( out != null && x != "pic" ) {
2022-06-07 13:36:28 +02:00
typeInTextarea ( out ) ;
2022-06-13 04:08:02 +02:00
var end = id . value . length ;
2022-06-07 13:36:28 +02:00
id . setSelectionRange ( end , end ) ;
2022-06-24 22:24:02 +02:00
id . focus ( { preventScroll : true } ) ;
2022-06-07 13:36:28 +02:00
}
2022-05-10 04:16:08 +02:00
}
2022-03-27 19:58:39 +02:00
function testor ( input ) {
let v1 = [ ] ;
input . forEach ( ( input ) => {
v1 . push ( "\"" + input . trim ( ) + "\"" ) ;
} ) ;
if ( v1 ) {
return v1 ;
} else {
return null ;
}
}
function showInput ( e ) {
2022-04-11 22:38:32 +02:00
var display = document . getElementById ( "result" ) ;
2022-06-26 15:04:39 +02:00
display . innerHTML = '' ;
e . preventDefault ( ) ;
display . style . display = "flex" ;
2022-03-27 19:58:39 +02:00
var d = new Date ( ) ;
2022-04-10 02:24:33 +02:00
var datestring = d . getFullYear ( ) + "-" + ( "0" + ( d . getMonth ( ) + 1 ) ) . slice ( - 2 ) + "-" + ( "0" + d . getDate ( ) ) . slice ( - 2 ) + "T" + ( "0" + d . getHours ( ) ) . slice ( - 2 ) + ":" + ( "0" + d . getMinutes ( ) ) . slice ( - 2 ) + ":00+02:00" ;
2022-06-25 05:36:48 +02:00
var datestring _shorter = d . getFullYear ( ) + "-" + ( "0" + ( d . getMonth ( ) + 1 ) ) . slice ( - 2 ) + "-" + ( "0" + d . getDate ( ) ) . slice ( - 2 ) ;
2022-03-27 19:58:39 +02:00
2022-06-13 04:08:02 +02:00
var form = document . querySelector ( 'form[id="generatorform"]' ) ;
2022-04-06 17:51:02 +02:00
var title = form . elements [ 'title' ] . value ;
2022-06-13 04:08:02 +02:00
var summary = form . elements [ 'summary' ] . value ;
2022-03-27 19:58:39 +02:00
var content = form . elements [ 'content' ] . value ;
2022-04-06 17:51:02 +02:00
var when = form . elements [ 'when' ] . value ;
2022-04-10 02:27:54 +02:00
var covid = form . elements [ 'covid' ] . value ;
2022-04-06 17:51:02 +02:00
var price = form . elements [ 'price' ] . value ;
2022-04-28 17:39:10 +02:00
var contact _mail = form . elements [ 'contact_mail' ] . value ;
var insta = form . elements [ 'insta' ] . value ;
2022-04-04 00:42:08 +02:00
var events = check _checkboxes ( 'events' ) ;
2022-06-24 13:51:48 +02:00
if ( form . elements [ 'events' ] ) { var newevents = testor ( form . elements [ 'events' ] . value . split ( ',' ) ) ; }
2022-06-22 16:24:36 +02:00
var news = check _checkboxes ( 'news' ) ;
2022-06-24 13:51:48 +02:00
if ( form . elements [ 'news' ] ) { var newnews = testor ( form . elements [ 'news' ] . value . split ( ',' ) ) ; }
2022-03-27 19:58:39 +02:00
var tags = check _checkboxes ( 'tags' ) ;
2022-06-24 13:51:48 +02:00
if ( form . elements [ 'tags' ] ) { var newtags = testor ( form . elements [ 'tags' ] . value . split ( ',' ) ) ; }
2022-03-27 19:58:39 +02:00
var featured = check _checkboxes ( 'featured' ) ;
2022-04-04 01:13:42 +02:00
var about = check _checkboxes ( 'about' ) ;
2022-04-28 17:55:16 +02:00
var recurrent = check _checkboxes ( 'recurrent' ) ;
2022-03-27 19:58:39 +02:00
2022-04-10 14:06:48 +02:00
var foundations = check _checkboxes ( 'foundations' ) ;
2022-06-24 13:51:48 +02:00
if ( form . elements [ 'foundations' ] ) { var newfoundations = testor ( form . elements [ 'foundations' ] . value . split ( ',' ) ) ; }
2022-04-10 14:06:48 +02:00
2022-04-10 02:24:33 +02:00
var lastmod = form . elements [ 'lastmod' ] . value ;
if ( lastmod ) {
var dl = new Date ( lastmod ) ;
var lastmod = dl . getFullYear ( ) + "-" + ( "0" + ( dl . getMonth ( ) + 1 ) ) . slice ( - 2 ) + "-" + ( "0" + dl . getDate ( ) ) . slice ( - 2 ) + "T" + "14:" + "00:00+02:00" ;
}
2022-03-27 19:58:39 +02:00
2022-04-04 00:42:08 +02:00
if ( newtags != '""' ) {
var ntags = newtags ;
2022-03-27 19:58:39 +02:00
}
if ( tags != '' ) {
var ntags = tags ;
}
2022-04-04 00:42:08 +02:00
if ( tags != '' && newtags != '""' ) {
var ntags = tags + "," + newtags ;
2022-03-27 19:58:39 +02:00
}
2022-06-08 06:09:50 +02:00
2022-06-22 16:24:36 +02:00
if ( newnews != '""' ) {
var nnews = newnews ;
2022-04-04 00:42:08 +02:00
}
2022-06-22 16:24:36 +02:00
if ( news != '' ) {
var nnews = news ;
2022-04-04 00:42:08 +02:00
}
2022-06-22 16:24:36 +02:00
if ( news != '' && newnews != '""' ) {
var nnews = news + "," + newnews ;
2022-04-04 00:42:08 +02:00
}
2022-04-06 17:51:02 +02:00
if ( newevents != '""' ) {
var nevents = newevents ;
}
if ( events != '' ) {
var nevents = events ;
}
if ( events != '' && newevents != '""' ) {
var nevents = events + "," + newevents ;
}
2022-06-24 17:04:47 +02:00
if ( nnews ) {
if ( alltags ) {
var alltags = alltags + "," + nnews ;
} else {
var alltags = nnews ;
}
}
if ( nevents ) {
if ( alltags ) {
var alltags = alltags + "," + nevents ;
} else {
var alltags = nevents ;
}
}
if ( ntags ) {
if ( alltags ) {
var alltags = alltags + "," + ntags ;
} else {
var alltags = ntags ;
}
}
2022-04-06 17:51:02 +02:00
2022-04-10 14:06:48 +02:00
if ( newfoundations != '""' ) {
var nfoundations = newfoundations ;
}
if ( foundations != '' ) {
var nfoundations = foundations ;
}
if ( foundations != '' && newfoundations != '""' ) {
var nfoundations = foundations + "," + newfoundations ;
}
2022-03-27 19:58:39 +02:00
if ( ! title ) {
display . innerHTML += "Title is missing..<br>"
}
2022-04-28 17:39:10 +02:00
2022-03-27 19:58:39 +02:00
2022-04-28 17:39:10 +02:00
if ( title ) {
2022-06-25 03:26:17 +02:00
var output = "---\n" ;
var output = output + "title: \"" + title . trim ( ) + "\"\n" ;
2022-06-26 15:04:39 +02:00
2022-04-10 14:54:59 +02:00
if ( lastmod ) {
2022-06-25 03:26:17 +02:00
var output = output + "lastmod: " + lastmod . trim ( ) + "\n" ;
2022-04-10 14:54:59 +02:00
} else {
2022-06-25 03:26:17 +02:00
var output = output + "date: " + datestring . trim ( ) + "\n" ;
2022-04-10 14:54:59 +02:00
}
2022-06-26 15:04:39 +02:00
2022-03-27 20:14:36 +02:00
if ( featured != '' ) {
2022-06-25 03:26:17 +02:00
var output = output + "featured: true\n" ;
2022-03-27 20:14:36 +02:00
}
2022-03-27 19:58:39 +02:00
2022-04-04 01:13:42 +02:00
if ( about != '' ) {
2022-06-25 03:26:17 +02:00
var output = output + "about: true\n" ;
2022-04-04 01:13:42 +02:00
}
2022-04-28 17:55:16 +02:00
if ( recurrent != '' ) {
2022-06-25 03:26:17 +02:00
var output = output + "recurrent: true\n" ;
2022-04-28 17:55:16 +02:00
}
2022-04-03 21:08:42 +02:00
if ( when ) {
2022-06-25 03:26:17 +02:00
var output = output + "when: \"" + when + "\"\n" ;
2022-04-03 21:08:42 +02:00
}
2022-06-26 15:04:39 +02:00
2022-06-22 16:24:36 +02:00
if ( nnews ) {
2022-06-25 03:26:17 +02:00
var output = output + "news: \[" + nnews + "]\n" ;
2022-03-27 20:14:36 +02:00
}
2022-03-27 19:58:39 +02:00
2022-04-06 19:32:09 +02:00
if ( nevents ) {
2022-06-25 03:26:17 +02:00
var output = output + "events: \[" + nevents + "]\n" ;
2022-03-27 20:14:36 +02:00
}
2022-06-26 15:04:39 +02:00
2022-04-10 14:06:48 +02:00
if ( nfoundations ) {
2022-06-25 03:26:17 +02:00
var output = output + "foundations: \[" + nfoundations + "]\n" ;
2022-04-10 14:06:48 +02:00
}
2022-06-26 15:04:39 +02:00
2022-06-24 17:04:47 +02:00
if ( alltags ) {
2022-06-25 03:26:17 +02:00
var output = output + "tags: \[" + alltags + "]\n" ;
2022-03-27 20:14:36 +02:00
}
2022-04-10 02:27:54 +02:00
if ( covid ) {
2022-06-25 03:26:17 +02:00
var output = output + "covid: \"" + covid + "\"\n" ;
2022-04-10 02:27:54 +02:00
}
2022-04-03 21:08:42 +02:00
if ( price ) {
2022-06-25 03:26:17 +02:00
var output = output + "price: \"" + price + "\"\n" ;
2022-04-03 21:08:42 +02:00
}
2022-04-10 14:54:59 +02:00
2022-04-28 17:39:10 +02:00
if ( contact _mail ) {
2022-06-25 03:26:17 +02:00
var output = output + "contact_mail: \"" + contact _mail + "\"\n" ;
2022-04-28 17:39:10 +02:00
}
if ( insta ) {
2022-06-25 03:26:17 +02:00
var output = output + "insta: \"" + insta + "\"\n" ;
2022-04-03 21:08:42 +02:00
}
2022-06-25 03:26:17 +02:00
var output = output + "---\n" ;
2022-06-13 04:08:02 +02:00
if ( summary ) {
2022-06-26 15:04:39 +02:00
var output = output + summary . trim ( ) + "\n" + "<!--more-->" + "\n" ;
2022-06-13 04:08:02 +02:00
}
2022-03-27 20:14:36 +02:00
if ( content ) {
2022-06-25 03:26:17 +02:00
var output = output + content . trim ( ) ;
2022-03-27 20:14:36 +02:00
}
2022-06-25 03:26:17 +02:00
// Add an top-level, arbitrary text file with contents
zip . file ( "index.de.md" , output ) ;
2022-06-25 05:36:48 +02:00
var pattern = /[^a-z\d\-_\s]+$/i ;
var t = title . replace ( /^["'](.+(?=["']$))["']$/ , '$1' ) . toLowerCase ( ) ;
var t = t . trim ( ) ;
var t = t . replaceAll ( /\s+/g , '-' ) ;
2022-06-25 03:26:17 +02:00
2022-06-25 05:36:48 +02:00
var t = t . replace ( /[^\w.-]+/g , "" ) ;
2022-06-26 15:04:39 +02:00
archive _name = datestring _shorter + "-" + t + ".zip" ;
2022-06-25 05:36:48 +02:00
2022-06-26 15:04:39 +02:00
var check _banner = false ;
2022-06-25 05:36:48 +02:00
2022-06-26 15:04:39 +02:00
for ( let [ filename , file ] of Object . entries ( zip . files ) ) {
console . log ( filename ) ;
if ( filename . startsWith ( "banner" ) ) { check _banner = true ; }
}
if ( output ) {
display . innerHTML += "<button style=\"background: #69c839;\" class=\"button\" onclick=\"dl_archive()\" type=\"button\" \">Save Archive</button><br>" ;
if ( check _banner == false ) {
2022-06-26 15:44:32 +02:00
display . innerHTML += "<br>\n<div>Banner (1920x850px) missing</div>"
}
if ( ! ( summary ) ) {
display . innerHTML += "<br>\n<div>Summary missing</div>"
}
if ( ! ( content ) ) {
display . innerHTML += "<br>\n<div>Content missing</div>"
2022-06-26 15:04:39 +02:00
}
}
2022-03-27 19:58:39 +02:00
}
}
2022-06-26 15:04:39 +02:00
function dl _archive ( ) {
// Generate the zip file asynchronously
zip . generateAsync ( { type : "blob" } )
. then ( function ( cont ) {
// Force down of the Zip file
saveAs ( cont , archive _name ) ;
} ) ;
}