Last active
January 6, 2020 13:10
-
-
Save ailispaw/a1934684cdee9a10506a to your computer and use it in GitHub Desktop.
Fix Tumblr.iframe 2017.01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==Taberareloo== | |
// { | |
// "name" : "Fix Tumblr.iframe 2017.01" | |
// , "description" : "Fix Tumblr.iframe 2017.01" | |
// , "include" : ["content"] | |
// , "match" : ["*://*/*"] | |
// , "version" : "0.2.2" | |
// , "downloadURL" : "https://gist.githubusercontent.com/ailispaw/a1934684cdee9a10506a/raw/patch.fix.tumblr.iframe.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function() { | |
addAround(Extractors['ReBlog'], 'getFrameUrl', function (proceed, args, target, methodName) { | |
var doc = args[0]; | |
var url = proceed(args); | |
if (!url) { | |
var tumblr_controls = doc.querySelector('iframe[name="desktop-loggedin-controls"]') || | |
doc.querySelector('iframe[name="desktop-logged-in-controls"]') || | |
doc.querySelector('iframe[name="unified-controls"]'); | |
if (tumblr_controls && (queryHash(unescapeHTML(tumblr_controls.src)).postId || queryHash(unescapeHTML(tumblr_controls.src)).pid)) { | |
return tumblr_controls.src; | |
} | |
} | |
return url; | |
}); | |
addAround(Extractors['ReBlog'], 'extractByPage', function (proceed, args, target, methodName) { | |
var that = target; | |
var ctx = args[0]; | |
var doc = args[1]; | |
if (!(ctx.reblog_id && ctx.reblog_key)) { | |
var params = queryHash(unescapeHTML(that.getFrameUrl(doc))); | |
if (params.postId) { // new type | |
var anchor = $N('a', {href: doc.URL}); | |
return request(anchor.origin + '/api/read', { | |
queryString: { | |
id: params.postId | |
} | |
}).then(function (res) { | |
var xml = res.responseXML; | |
var post = xml.querySelector('post'); | |
ctx.reblog_id = post.getAttribute('id'); | |
ctx.reblog_key = post.getAttribute('reblog-key'); | |
return that.extractByPage(ctx, doc); | |
}); | |
} | |
if (params.pid && params.rk) { // old type | |
ctx.reblog_id = params.pid; | |
ctx.reblog_key = params.rk; | |
} else if (params.pid) { // new type | |
var anchor = $N('a', {href: doc.URL}); | |
return request(anchor.origin + '/api/read', { | |
queryString: { | |
id: params.pid | |
} | |
}).then(function (res) { | |
var xml = res.responseXML; | |
var post = xml.querySelector('post'); | |
ctx.reblog_id = post.getAttribute('id'); | |
ctx.reblog_key = post.getAttribute('reblog-key'); | |
return that.extractByPage(ctx, doc); | |
}); | |
} else if (/^http:\/\/[^.]+\.tumblr\.com\/post\/\d+/.test(doc.URL)) { | |
var anchor = $N('a', {href: doc.URL}); | |
return request(anchor.origin + '/api/read', { | |
queryString: { | |
id: anchor.pathname.replace('/post/', '') | |
} | |
}).then(function (res) { | |
var xml = res.responseXML; | |
var post = xml.querySelector('post'); | |
ctx.reblog_id = post.getAttribute('id'); | |
ctx.reblog_key = post.getAttribute('reblog-key'); | |
return that.extractByPage(ctx, doc); | |
}); | |
} else { | |
throw new Error("Invalid iFrame URL"); | |
} | |
} | |
if (!ctx.post_type) { | |
ctx.post_type = false; | |
} | |
return that.getFormKeyAndChannelId().then(function () { | |
return that.extractByEndpoint(ctx, that.TUMBLR_URL + 'reblog/' + ctx.reblog_id + '/' + ctx.reblog_key); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment