-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebJournal_maker.ps1
More file actions
291 lines (254 loc) · 6.48 KB
/
WebJournal_maker.ps1
File metadata and controls
291 lines (254 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# MANDATORY variables
#Path of the HTML report
$File = ""
# BAS automation executable file path
$BAS = ""
# Canary file to signal HTML completion, MUST be set as last action in BAS script
$Canary = "" # Path of the empty file (canary) that will be created and deleted for script timing
# CONTENT variables to fill the report
$ImgPath = "" # Path of the images folder
$LinkFile = "" # Path of the file with the images sites links
$TextFile = "" # Path of the text file
$MemeFold = "" # Path of the folder with images for displaying a random one
# OPTIONAL
$Sites = "" # Open these sites waiting for BAS to complete its execution: "site1", "site2", etc.
if ($sites -ne "") {
foreach ($site in $Sites) {
Start-Process "$site"
}
}
# FROM HERE ON, CHANGE ONLY FOR TROUBLESHOOTING OR CUSTOMIZATION
Invoke-item $BAS
# Variables for custom local images
if ($MemeFold -ne ""){
$meme = Get-ChildItem -Path $MemeFold -File | Get-Random
$memeBytes = [System.IO.File]::ReadAllBytes($meme.fullname)
$meme64 = [Convert]::ToBase64String($memeBytes)
$memeOut = $meme64.Replace("``r``n", "").Replace("``n", "").Replace(" ", "")
}
# Wait for the bot to finish and delete canary file
while ((Test-Path $Canary) -eq $false) {
Start-Sleep -Seconds 3
}
Remove-Item -Path $Canary -Force
# Create beginning of HTML file
@"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<style>
body {
background-color: #242424
}
img {
object-position: center center;
}
.flex-container {
display: flex;
justify-content: space-between;
padding: 10px;
background-color: #2d3a49;
color: #ffffff;
margin-bottom: 10px;
}
* {
box-sizing:border-box;
}
.slideshow-container {
display: flex;
justify-content: center;
align-items: center;
position: relative;
margin: auto;
min-height: 75vh;
}
.mySlides {
display: none; /* Hide the images by default */
text-align: center;
margin: auto;
}
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
user-select: none;
background-color: rgba(0,0,0,0.5);
}
.next {
right: 0;
border-radius: 0 3px 3px 0;
z-index: 10;
}
.prev {
left: 0;
border-radius: 3px 0 0 3px;
z-index: 10;
}
/* On hover add a black background with a little see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
.numbertext {
color: #00CCFF;
font-size: 14px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.0s;
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
.responsive-hr {
width: 80vw;
border: none;
height: 4px;
background-color: #ccc;
}
</style>
<title> WEB JOURNAL </title>
<body>
"@ > $File
# Adding HTML page header
$intro = "Slideshow: ARROW KEYS and SPACE"
$title = "~ WEB JOURNAL ~"
$date = "Generated on: $(Get-Date)"
@"
<div class="flex-container">
<span>$intro</span>
<span><strong>$title</strong></span>
<span>$date</span>
</div>
<div class="slideshow-container">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
"@ >> $File
# Insert images for the slideshow
if ($ImgPath -ne "") {
$num = -1
$slide = 1
$tot = $(Get-ChildItem $ImgPath).length
foreach ($Im in (Get-ChildItem $ImgPath)) {
$imBytes = [System.IO.File]::ReadAllBytes($Im.fullname)
$base64Im = [Convert]::ToBase64String($imBytes)
$base64Image = $base64Im.Replace("``r``n", "").Replace("``n", "").Replace(" ", "")
[int]$num = [int]$num+1
if ($LinkFile -ne "") {
$Link = Get-Content $LinkFile
$nLink = $link[$num]
} else {
$nLink = " "
}
@"
<div class="mySlides fade">
<div class="numbertext">$slide / $tot
</div>
<a href = $nLink target="_blank"><img src=data:image/jpeg;base64,$base64Image>
</a>
</div>
"@ >> $File
[int]$slide = [int]$slide+1
}
}
# Close the sliedesohw div, even if it's empty
"</div>" >> $File
# Add text below the slideshow
if ($TextFile -ne "") {
$text = Get-Content $TextFile -Encoding UTF8
@"
<br>
<div>
<p style="color: white;">
$text
</p>
</div>
"@ >> $File
}
# Add one random local image from a chosen images folder
if ($meme -ne $null) {
@"
<br>
<div>
<p>
<h2 style="text-align: center; color: #FFFFFF"> Random image </h2>
</p>
<div style="display: flex; justify-content: center">
<img src="data:image/jpeg;base64,$memeOut">
</div>
</div>
<hr class=responsive-hr; style="width:100%">
"@ >> $File
}
# Close HTML code and add JavaScrpit
@"
</body>
</html>
<script>
let slideIndex = 1;
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
};
// Cycle through slides
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
slides[i].classList.remove('active');
}
slides[slideIndex - 1].style.display = "block";
slides[slideIndex - 1].classList.add('active');
};
// Image showing
function currentSlide(n) {
showSlides(slideIndex = n);
};
// Browse slides with arrow keys
document.addEventListener('keydown', function(event) {
// Left arrow key code is 37
if (event.key === 'ArrowLeft' || event.keyCode === 37) {
plusSlides(-1); // Go to previous slide
}
// Right arrow key code is 39
else if (event.key === 'ArrowRight' || event.keyCode === 39) {
plusSlides(1); // Go to next slide
}
});
// Press space key to open link
document.addEventListener('keydown', function(event) {
// Check if SPACE key was pressed
if (event.key === ' ') {
event.preventDefault(); // Prevent scrolling down the page
// Find the currently visible image
const activeSlide = document.querySelector('.slideshow-container .mySlides.active');
// Check if the active image has a parent link
if (activeSlide && activeSlide.querySelector('a')) {
const link = activeSlide.querySelector('a');
window.open(link.href, '_blank');
}
}
});
// Execute
showSlides(slideIndex);
</script>
"@ >> $File
# Open HTML report
Invoke-item $File