Skip to content

Instantly share code, notes, and snippets.

@Megafry
Megafry / GeminiProvider.php
Created June 1, 2026 19:55
Test: Registering a custom API provider for digitalpulsebe craft-multi-translator
<?php
declare(strict_types=1);
namespace modules\translator\providers;
use Craft;
use craft\helpers\App;
use digitalpulsebe\craftmultitranslator\providers\Provider;
use digitalpulsebe\craftmultitranslator\MultiTranslator;
<?php
namespace modules\ExtendCraft\variables;
use craft\elements\Entry;
use Craft;
use craft\elements\MatrixBlock;
use craft\services\Fields;
class ExtendCraft
@Megafry
Megafry / scrollIntoView.js
Created May 7, 2025 13:29
Stop using window.scrollTo(), Use the new scrollIntoView, this will also take into consideration the scroll-padding defined in CSS.
button.addEventListener('click', e => {
const targetEl = document.getElementById("footer")
targetEl.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start'})
})
@Megafry
Megafry / LifeguardController.php
Last active May 5, 2025 09:05
CraftCMS form to update single via Front-End User login
<?php
namespace modules\lifeguard\controllers;
use Craft;
use craft\elements\Entry;
use craft\web\Controller;
use yii\web\Response;
/**
@Megafry
Megafry / gist:8da833eb5ebd1e0b3be3dfa1554043af
Created October 26, 2021 13:47
Regex xml to xlf (TYPO3)
## Default (locallang.xml to locallang.xlf)
## search
<label index="(.*?)">(.*?)</label>
## replace
<trans-unit id="$1">\n\t<source>$2</source>\n</trans-unit>
## langauge (locallang.xml to de.locallang.xlf)
## search
<label index="(.*?)">(.*?)</label>
## replace
@Megafry
Megafry / G201.typoscript
Last active November 17, 2021 14:16
TYPO3: add warning text to all external links with regex
page.10.stdWrap.replacement {
10 {
search = #(<a.*?target="_blank".*?>)(.*?)(</a>)#i
replace {
wrap2 = ${1}${2} |${3}
noTrimWrap = |<span class="show-for-sr"> |</span>|
data = LLL:EXT:...locallang.xlf:link_open_in_new_windows
}
useRegExp = 1
}
@Megafry
Megafry / setClassRand.js
Created October 20, 2020 09:50
Adds the given class to 1 element from the selection and return it:
// extend jQuery:
$.fn.setClassRand = function(cssClass) {
return this.eq( Math.floor( Math.random() * this.length ) ).addClass(cssClass);
};
//usage:
//add the class "teaser__video--active" and play it:
var video = $(".teaser__video").setClassRand("teaser__video--active");
if (video.length) {
video[0].play();
@Megafry
Megafry / parseFunc.typoscript
Created September 23, 2020 11:29
TypoScript to extend TYPO3 lib.parseFunc by adding the file-extention as data attribute without userFunc.
lib.parseFunc {
tags.a.typolink {
ATagParams.stdWrap.cObject = FILES
ATagParams.stdWrap.cObject {
stdWrap.if {
isPositive.data = parameters:href
isPositive.stdWrap.replacement {
10 {
search = t3://file?uid=
replace =
@Megafry
Megafry / parseFunc.typoscript
Last active November 5, 2020 13:46
TypoScript to extend TYPO3 parseFunc, adding the file-extention and size to all link
lib.parseFunc {
tags.a.typolink {
#add text in the A-Tag
ATagBeforeWrap = 1
wrap.cObject = FILES
wrap.cObject {
#get file ID
files.stdWrap {
data = parameters:href
stdWrap.replacement {
@Megafry
Megafry / .htaccess
Created May 14, 2020 08:38
Favicon redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} webpage2\.com$ [NC]
RewriteRule ^favicon\.ico$ /webpage2_favicon.ico [L,NC]