([\\s\\S]*?)<\/div>': '\n```\n$1\n```\n',
// TODO: Fix noparse. It's not working properly. Do PR if you can fix it.
// Tables
// TODO: Fix bb_table. It's not working properly. Do PR if you can fix it.
// TODO: Fix bb_table_tr. It's not working properly. Do PR if you can fix it.
// TODO: Fix bb_table_th. It's not working properly. Do PR if you can fix it.
// TODO: Fix bb_table_td. It's not working properly. Do PR if you can fix it.
// Images
'

]*>': '',
// Others
'
': '---',
'
([\\s\\S]*?)
' : '> $1',
};
// Apply custom replacements
for (var pattern in mdReplacements) {
var regex = new RegExp(pattern, 'gi');
descriptionHTML = descriptionHTML.replace(regex, mdReplacements[pattern]);
}
// Clear unsupported tags except for
Spoiler
$1
descriptionHTML = descriptionHTML.replace(/<(?!details>
Spoiler<\/summary>\$1<\/details>)[^>]+>/g, '');
var markdownContent = descriptionHTML;
return markdownContent;
}
function insertButton(downloadButton) {
var fixedMargin = document.querySelector('.game_area_purchase_margin');
if (fixedMargin) {
// Better alignment ...
fixedMargin.style.marginBottom = 'auto';
// Find the element after which the button should be inserted
var targetElement = document.querySelector('.workshopItemDescription');
if (targetElement) {
// Insert the button after the target element
targetElement.parentNode.insertBefore(downloadButton, targetElement.nextSibling);
}
}
}
// Create go to repo button
function createGoToRepoButton() {
var goToRepoButton = document.createElement('a');
goToRepoButton.innerHTML = '
Repository';
goToRepoButton.classList.add('btn_darkblue_white_innerfade', 'btn_border_2px', 'btn_medium');
goToRepoButton.style.marginBottom = '5px';
goToRepoButton.style.marginRight = '5px';
goToRepoButton.style.padding = '5px 10px';
goToRepoButton.style.height = '21px';
goToRepoButton.style.fontSize = '14px';
goToRepoButton.href = 'https://github.com/criskkky/SWDD';
goToRepoButton.target = '_blank';
insertButton(goToRepoButton);
}
// Create the download button for Markdown
function createDownloadButtonMD() {
var downloadButton = document.createElement('button');
downloadButton.innerHTML = '
Download .MD';
downloadButton.classList.add('btn_green_white_innerfade', 'btn_border_2px', 'btn_medium');
downloadButton.style.marginBottom = '5px';
downloadButton.style.marginRight = '5px';
downloadButton.style.padding = '5px 10px';
downloadButton.style.height = '34.43px';
downloadButton.style.fontSize = '14px';
downloadButton.addEventListener('click', function () {
var markdownContent = getHTMLtoMD(getDescription());
if (markdownContent) {
downloadContent(markdownContent, 'WorkshopDownload.md');
} else {
alert('No content found in Markdown format.');
}
});
insertButton(downloadButton);
}
// Create the download button for BBCode
function createDownloadButtonBBC() {
var downloadButton = document.createElement('button');
downloadButton.innerHTML = '
Download .BBCode';
downloadButton.classList.add('btn_green_white_innerfade', 'btn_border_2px', 'btn_medium');
downloadButton.style.marginBottom = '5px';
downloadButton.style.marginRight = '5px';
downloadButton.style.padding = '5px 10px';
downloadButton.style.height = '34.43px';
downloadButton.style.fontSize = '14px';
downloadButton.addEventListener('click', function () {
var bbcodeContent = getHTMLtoBBC(getDescription());
if (bbcodeContent) {
downloadContent(bbcodeContent, 'WorkshopDownload.bbcode');
} else {
alert('No content found in BBCode format.');
}
});
insertButton(downloadButton);
}
// Execute the functions when the page loads
window.addEventListener('load', function () {
createGoToRepoButton();
createDownloadButtonMD();
createDownloadButtonBBC();
});