Skip to content

Commit

Permalink
remove lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Nov 22, 2024
1 parent d2e56bc commit 335504a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 217 deletions.
7 changes: 3 additions & 4 deletions Extensions/fresh_prince.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//* TITLE Fresh Prince **//
//* VERSION 0.1.1 **//
//* VERSION 0.1.2 **//
//* DESCRIPTION Everything's flipped, turned upside down **//
//* DEVELOPER new-xkit **//
//* DETAILS This extension flips everything on the dashboard. Don't expect Tumblr to function correctly whatsoever while this extension is installed. **//
Expand Down Expand Up @@ -76,7 +76,6 @@ XKit.extensions.fresh_prince = new Object({

if (!XKit.extensions.fresh_prince.preferences.disable_rotate.value) {
await XKit.css_map.getCssMap();
const {keyToCss, descendantSelector} = XKit.css_map;

XKit.tools.add_css(`
.l-header-container, .l-container, .l-footer-container {
Expand All @@ -90,11 +89,11 @@ XKit.extensions.fresh_prince = new Object({
transform: scale(1, -1);
}
${descendantSelector('menuContainer', 'baseContainer')} {
${XKit.css_map.descendantSelector('menuContainer', 'baseContainer')} {
transform: scale(1, -1);
}
${keyToCss('popoverChrome')} > * {
${XKit.css_map.keyToCss('popoverChrome')} > * {
transform: scale(1, -1);
}
Expand Down
78 changes: 2 additions & 76 deletions Extensions/xkit_patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,55 +119,6 @@ XKit.extensions.xkit_patches = new Object({
};
XKit.tools.add_function(blog_scraper, true);

XKit.tools.add_function(function fix_autoplaying_yanked_videos() {

if (!window._ || !window.jQuery) {
return;
}

if (_.get(window, "Tumblr.Prima.CrtPlayer")) {
window.Tumblr.Prima.CrtPlayer.prototype.onLoadedMetadata =
_.wrap(window.Tumblr.Prima.CrtPlayer.prototype.onLoadedMetadata,
function(wrapped, _event) {
if (!this.$el.is(":visible") || !jQuery.contains(document, this.$el[0])) {
if (!this.$el.find('video[src^="blob:"]').length) {
return true;
}
}
return wrapped.call(this, _event);
});
}

// unfortunately we're not fast enought to catch some
// CRT instances that are currently instantiated, so handle those differently
jQuery('video').parent().each(function() {
this.addEventListener('loadedmetadata', function(event) {
var $target = jQuery(event.target);
if (!$target.is(":visible") || !jQuery.contains(document, event.target)) {
event.stopPropagation();
}
}, true); // uses .parent() and capturing to preempt tumblr's js
});
}, true, {});

XKit.tools.add_function(function fix_jk_scrolling() {
if (!window._ || !window.jQuery) {
return;
}

if (_.get(window, "Tumblr.KeyCommands.update_post_positions")) {
Tumblr.KeyCommands.update_post_positions = _.wrap(Tumblr.KeyCommands.update_post_positions,
function(wrapped, _event) {
wrapped.call(this);
this.post_positions = _.pick(this.post_positions,
function(scroll_pos, element_id) {
var element = jQuery("[data-pageable='" + element_id + "']");
return element.is(":visible") && element.height() > 0;
});
});
}
}, true, {});

setTimeout(function() {

var form_key_to_save = $('meta[name=tumblr-form-key]').attr("content");
Expand Down Expand Up @@ -289,30 +240,6 @@ XKit.extensions.xkit_patches = new Object({
});
};

/**
* Removes the leading whitespace that occurrs on every line of
* `string`, and replaces it with the string passed in as `level`.
* This is often helpful for making the output of template strings
* more readable, by normalizing the additional indentation that
* comes with their position in a source file.
*
* @param {String} level - the amount of indentation to add to
* every line, as a string. May be '' for no indentation.
* @param {String} string - the input string to remove and/or add
* indentation from/to.
* @returns {String} - the normalized string
*/
XKit.tools.normalize_indentation = (level, string) => {
const lines = string.split("\n");
const indentation_level = _.minBy(
lines.map(line => line.match(/^[ \t]+/)),
i => i ? i[0].length : Infinity
) || '';

const leading_indentation = new RegExp(`^${indentation_level}`);
return lines.map(line => line.replace(leading_indentation, level)).join("\n");
};

/**
* Gets redpop translation strings for selecting elements via aria labels
* @param {String} key - en_US string to translate
Expand Down Expand Up @@ -380,7 +307,7 @@ XKit.extensions.xkit_patches = new Object({
script.textContent = "var add_tag = " + JSON.stringify(addt) + ";\n";
script.textContent = script.textContent +
(exec ? "(" : "") +
XKit.tools.normalize_indentation('', func.toString()) +
func.toString() +
(exec ? ")();" : "");
if (XKit.tools.add_function_nonce) {
script.setAttribute('nonce', XKit.tools.add_function_nonce);
Expand Down Expand Up @@ -425,7 +352,7 @@ XKit.extensions.xkit_patches = new Object({

const add_func = `(async ({callback_nonce, args}) => {
try {
const return_value = await (${XKit.tools.normalize_indentation("\t".repeat(7), func.toString())})(args);
const return_value = await (${func.toString()})(args);
window.postMessage({
xkit_callback_nonce: callback_nonce,
Expand Down Expand Up @@ -731,7 +658,6 @@ XKit.extensions.xkit_patches = new Object({
).map(selectors => selectors.join(' ')).join(',');
},
};
_.bindAll(XKit.css_map, ['getCssMap', 'keyToClasses', 'keyToCss', 'descendantSelector']);

// eslint-disable-next-line no-async-promise-executor
XKit.tools.Nx_XHR = details => new Promise(async (resolve, reject) => {
Expand Down
1 change: 0 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
],
"js": [
"bridge.js",
"vendor/lodash.min.js",
"vendor/jquery.js",
"vendor/tiptip.js",
"vendor/moment.js",
Expand Down
Loading

0 comments on commit 335504a

Please sign in to comment.