나는 길을 발견했다. 그러나 그것은 완전히 신뢰할 수는 없으며, 언어와 아마도 OS에 달려있다.
텀블러 컨트롤 바의 크기는 3 가능한 상황에서 다릅니다
261x 및 36이
190x26
가 로그인 (이 블로그의 이름에 따라 다름)에 로그인하지 않은, 관리자
179x26에 로그인했으나 관리자가 없습니다
그래서 사용자가 로그인 한 상태라면 S 코드 : 우리는 여전히 인정할 수있는 값의 범위를 지정할 수 있습니다 tolerance
와
//true: the current user is an admin
//false: the current user is not an admin
//'ask-later': the bar is not ready yet
//'dont-know': the bar is not there
function isAdmin (tolerance) {
// source: http://stackoverflow.com/a/27506229/288906
//these values are expected for English blogs
var EXPECTED_WIDTH = 190;
var EXPECTED_HEIGHT = 26;
tolerance = tolerance || 10;
var controls = document.getElementById('tumblr_controls');
if(!controls) {
//the bar is not there
return 'dont-know';
}
if(controls.width === '1') {
//the bar is not ready, try later
return 'ask-later';
}
var differenceW = Math.abs(controls.width - EXPECTED_WIDTH)
var differenceH = Math.abs(controls.height - EXPECTED_HEIGHT);
return differenceW + differenceH < tolerance;
}
, 그래서 195x28 여전히 작동 할 수 있습니다. 이 코드는 암호로 보호 된 블로그에서 해당 막대를 표시하지 않으므로 작동하지 않습니다.
약속과 비동기로 만들면 개선 될 수 있으므로 "아직 준비되지 않음"상태는 피할 수 있습니다.
로그인하고 볼 때 테마를 팔로우하거나 편집 할 수있는 옵션이 있으므로 사이드 블로그의 경우이를 수정해야합니다. – chloe784