Eye-friendly magic in your browser for Shuttle API
当前为
//
// Written by Glenn Wiking
// Script Version: 0.1.2
//
//
// ==UserScript==
// @name Shuttle SEO Master
// @namespace SSM
// @description Eye-friendly magic in your browser for Shuttle API
// @version 0.1.2
// @icon https://dlw0tascjxd4x.cloudfront.net/assets/img/symbol.svg
// @include *.shuttle.be/admin/*
// @include *app.shuttle.be/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @require https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js
// ==/UserScript==
$(window).on("load", function() {
// SEO Form Element Characters
setInterval( function() {
let descs = $("textarea[name*='meta_description']:not(.affected), textarea[id^='languages']:not(.affected), input#og_description:not(.affected), input[name*='meta_title']:not(.affected), input[name*='og_title']:not(.affected), input[name*='seo_titel']:not(.affected), textarea[name*='seo_omschrijving']:not(.affected)");
descs.each( function() {
$(this).parent().attr("limit", 150);
if ( $(this).closest("form").find("input#key").length ) {
if ( $(this).closest("form").find("input#key").val().includes("title") ) {
$(this).parent().attr("limit", 60);
}
}
if ( $(this).attr("name").includes("meta_title") || $(this).attr("name").includes("og_title") || $(this).attr("name").includes("seo_titel") ) {
$(this).parent().attr("limit", 60);
}
});
$(".seo-parent[limit='150']").attr("lowerlimit",50);
function check() {
const limit = parseInt( $(this).parent().attr("limit") );
const lowerLimit = parseInt( $(this).parent().attr("lowerlimit") );
$(this).parent().attr("length", $(this).val().length );
$(this).parent().addClass("seo-parent");
if ( $(this).val().includes("@") ) {
console.log("Dynamic");
$(this).closest(".seo-parent").addClass("dyn");
if ( ! $(this).val().includes("truncate(") ) {
console.log("Not Truncated");
$(this).parent().addClass("unknown").removeClass("known");
} else {
//console.log("Truncated");
//let trimmed = parseInt( $(this).val().split("truncate(")[1].substr(0,5) ); // 2 Characters Over, Should Be: ") "
let trimmed = 0;
let totalTrunc = 0;
let truncations = 0;
$(this).val().split(" ").forEach( function(val, i) {
if ( val.substr(0,1) == "@" ) {
//console.log( "%c" + val, "color:#B66" );
let trunc = parseInt( val.split("truncate(")[1].substr(0,5) );
trimmed = trimmed + trunc;
totalTrunc = totalTrunc + trunc;
if ( val.includes("truncate(") ) {
truncations = truncations + 1;
}
} else {
//console.log( "%c" + val, "color:#66B" );
trimmed = trimmed + val.length;
}
//console.log(truncations);
});
trimmed = trimmed + ( $(this).val().split(" ").length - 1 )
$(this).parent().attr("remainder", trimmed - totalTrunc).attr("trunc", totalTrunc);
console.log( trimmed );
$(this).parent().attr("length", trimmed);
$(this).parent().removeClass("unknown").addClass("known");
if ( truncations > 1 ) { $(this).parent().addClass("multi") } else { $(this).parent().removeClass("multi") }
//if ( remainder == 0 ) { $(this).parent().removeAttr("remainder") }
}
} else {
$(this).closest(".seo-parent").removeClass("dyn known unknown");
}
if ( $(this).val().length == 0 ) { $(this).closest(".seo-parent").addClass("empty") } else { $(this).closest(".seo-parent").removeClass("empty") }
console.log( $(this).val() );
let length = parseInt( $(this).parent().attr("length") );
if ( length > limit ) {
$(this).parent().removeClass("tooshort").addClass("toolong");
} else if ( length < lowerLimit ) {
$(this).parent().removeClass("toolong").addClass("tooshort");
} else {
$(this).parent().removeClass("toolong tooshort");
}
console.log( $(this) );
console.log( parseInt( $(this).parent().attr("length") ) + " | " + $(this).val().length + " - " + limit + " | " + lowerLimit );
$(this).addClass("affected");
//$(this).closest(".seo-parent.dyn[length='NaN']").removeclass("known");
}
descs.off("click change input");
descs.on("click change input", check);
descs.each(check);
}, 1000);
});
function SEO(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
style.className = "pro";
head.appendChild(style);
}
SEO(
'.shuttle-Header:not(.pro) > div > div:last-child > div > div:last-child .Button::after {content: "SEO"; position: absolute; text-transform: uppercase; font-size: 10.5px; color: #2B2B2B !important; background: #EFEC27; opacity: 1 !important; padding: 1px 4px; border-radius: 7px; top: 1px; right: -3px; pointer-events: none;}'
+
'.seo-parent::after {content: attr(length) " / " attr(limit); position: absolute; bottom: 0; left: 0; transform: translateY(100%); font-size: 15px;}'
+
'.seo-parent.toolong::after, .seo-parent.tooshort:not(.unknown)::after, .seo-parent.empty[lowerlimit]::after, .seo-parent.empty[length="0"] {color: #F14949;}'
+
'.seo-parent.unknown::after {content: "? / " attr(limit)}'
+
'.seo-parent.known::after, .seo-parent.known.multi[trunc="NaN"]::after {content: "Truncated to: " attr(length) " / " attr(limit)}'
+
'.seo-parent.known.multi::after {content: "Truncated to " attr(trunc) " (+" attr(remainder) ") : " attr(length) " / " attr(limit)}'
+
'.seo-parent.known:not(.multi):not([remainder="0"])::after {content: "Truncated to " attr(trunc) " (+" attr(remainder) ") : " attr(length) " / " attr(limit)}'
+
'.seo-parent.unknown[length="NaN"]::after, .seo-parent.known[length="NaN"]::after, .seo-parent.dyn:not(.known)::after, .seo-parent.dyn.known[length="NaN"] {content: "? / " attr(limit) !important;}'
+
'.seo-parent.unknown:not([length="NaN"]):not(.dyn)::after {content: attr(length) " / " attr(limit) !important;}'
);